Click here to Skip to main content
15,909,440 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
passing two values in url treatment and city from home.php

and in show.php

I want to display data according to these two values if found

in data base city column goes like Delhi(single value) but treatment column goes like prp, fever, infection(multiple values in single cell)

my problem is how to select and display if url consists treatment = prp and city = mumbai
then display no data found because city has delhi

What I have tried:

$sql = "SELECT * FROM add_doctor WHERE city='".$city."' AND treatment ='".$treatment."'";
Posted
Updated 12-May-17 3:20am
Comments
Richard Deeming 12-May-17 8:03am    
So your problem is that there are no matching records in the database, and you don't know why it's not finding any data to display?

Also, storing multiple values in a single field is a very bad database design. You should normalize your database, and have the multiple treatment values in a separate table with a foreign-key link to the doctors table.

1 solution

Two changes to make.

1) Since you're using .php, you can save youself some trouble when using " as your string wrapper.
$sql = "SELECT * FROM add_doctor WHERE city='".$city."' AND treatment ='".$treatment."'";
Could be written: 
$sql = "SELECT * FROM add_doctor WHERE city='$city' AND treatment ='$treatment'";

The php parser will replace the $ variable at run-time.

Now, to your query. Rewrite to something like:
$sql = "SELECT * FROM add_doctor WHERE city='$city' AND treatment LIKE '%$treatment%'";
With the '%' wild-cards wrapping your diseases. This will match any string that contains the value in $treatment regardless of what surrounds it.

As noted in first comment, the design for the disease field is very bad.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900