|
Notices |
![]() |
|
Thread Tools | Rate Thread | Display Modes |
![]() |
#1 |
Registered User
Join Date: Aug 2016
Posts: 4
|
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 Last edited by alexwaston; 03-07-2017 at 07:54 PM.. |
![]() |
![]() |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Talk about search engine optimization and search engine website of a SEO must pay att | ruixuan | Search Engine Optimization | 9 | 07-06-2018 03:25 AM |
Search Neutrality | webguru11 | Search Engine Optimization | 7 | 06-01-2017 11:59 PM |
Tips For Improving Your Site’s Search Engine Positioning | theshawnchin | Search Engine Optimization | 6 | 04-18-2014 02:27 AM |
Benefits of Internet Marketing – Search Engine Optimization | theshawnchin | Search Engine Optimization | 0 | 01-23-2013 12:26 AM |
Yahoo Image Search Update | davidstone2922 | Yahoo | 2 | 12-15-2011 12:44 AM |