Select query - ignore search criteria if value is empty
Hi, I have a simple database that I am querying from PHP. I have a user input some constraints in via a form, and then want to return results from a SELECT query based on the constraints. What I have is working when both constraints are used. However, if one of the constraints is not specified by the user, the SELECT query is returning no results, which I think is because it seeing the constraint variable as empty.
How do I get the SELECT query to use the constraint if it is not empty, but to ignore it if it is empty? Here is what I tried earlier but it isn't working. I thought I could test for empty and use OR to ignore it. $query="SELECT * FROM food_items WHERE (type IN ('$foodtypes') OR ('$foodtypes') > '') AND ('$budget' > '' OR cost <= ('$budget')) "; In this example, type and cost are fields in the database and $foodtypes and $budget are variables taken from the user inputs. Thanks Relax: popular ringtones, hip hop ringtones, rap ringtones |
All times are GMT -7. The time now is 10:20 AM. |
Powered by vBulletin Copyright © 2020 vBulletin Solutions, Inc.