How to retrieve all, searching MySQL
Posted: Tue Jan 17, 2006 11:16 am
Hi,
I'm implementing a search function on my web page. The user will be able to enter a search string, but also to specify some search criteria from a dropdown menu. My question is the following: If the user doesn't specify any search criteria (leaves it empty) then I want the search to disregard it.
As the code stands, if the user left category empty MySQL would look for a product with the category="", how can I change that to category=ALL. I don't want to do it with PHP!!
Cheers
Michael
I'm implementing a search function on my web page. The user will be able to enter a search string, but also to specify some search criteria from a dropdown menu. My question is the following: If the user doesn't specify any search criteria (leaves it empty) then I want the search to disregard it.
As the code stands, if the user left category empty MySQL would look for a product with the category="", how can I change that to category=ALL. I don't want to do it with PHP!!
Code: Select all
$query = "SELECT url FROM product WHERE name LIKE '$new_search' AND category='$category'";Cheers
Michael