Page 1 of 1
[SOLVED] - LIKE Statement Issue
Posted: Wed Feb 06, 2008 10:16 pm
by iknownothing
Hey Guys,
I have the following code:
Code: Select all
$result = mysql_query("SELECT * FROM clientDetails WHERE $searchby LIKE '%$searchquery%' ORDER BY businessname");
$searchby is defined by a dropdown, containing all table column names (eg. Business Name)
I thought that this should work, but the search result shows ALL rows, instead of ones like the query. Does anyone know why?
Thanks.
Re: LIKE Statement Issue
Posted: Wed Feb 06, 2008 10:44 pm
by John Cartwright
what does
Code: Select all
echo "SELECT * FROM clientDetails WHERE $searchby LIKE '%$searchquery%' ORDER BY businessname";
output?
Re: LIKE Statement Issue
Posted: Wed Feb 06, 2008 10:53 pm
by Festy
iknownothing wrote:Hey Guys,
I have the following code:
Code: Select all
$result = mysql_query("SELECT * FROM clientDetails WHERE $searchby LIKE '%$searchquery%' ORDER BY businessname");
$searchby is defined by a dropdown, containing all table column names (eg. Business Name)
I thought that this should work, but the search result shows ALL rows, instead of ones like the query. Does anyone know why?
Thanks.
I'd suggest you to first run the query in phpmyadmin or whatever your mysql client is like this way -
- Run only the "SELECT * FROM clientDetails" part and analyze the results, if it's working fine then go ahead and include WHERE $searchby clause (you can manually add a value in place of $searchby) and analyze the result, it it's working fine then finally include the "LIKE '%$searchquery%' " part and analyze the results. If everything work fine, just copy and paste your query in your php file and enjoy. If something goes wrong in your query tweak it in the mysql client itself.
Re: LIKE Statement Issue
Posted: Wed Feb 06, 2008 11:13 pm
by iknownothing
Thanks for your help.
The echo showed me a very stupid error i made within my form.
Lets never speak of this again.
Thanks again.