Register on the forum now to remove ALL ads + popups + get access to tons of hidden content for members only!

Go Back   Site Owners Forums - Webmaster Forums > Web Programming > Programming General > PHP / mySQL

Notices


Reply
 
Thread Tools Rate Thread Display Modes
Old 02-22-2017, 08:39 PM   #1
alexwaston
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 06:54 PM..
alexwaston is offline   Reply With Quote

Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
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 7 06-15-2015 03:30 AM
Tips For Improving Your Site’s Search Engine Positioning theshawnchin Search Engine Optimization 7 04-18-2014 02:27 AM
Benefits of Internet Marketing – Search Engine Optimization theshawnchin Search Engine Optimization 1 04-17-2014 02:48 AM
Yahoo Image Search Update davidstone2922 Yahoo 2 12-14-2011 11:44 PM
Search Neutrality webguru11 Search Engine Optimization 2 12-12-2011 12:25 AM


All times are GMT -7. The time now is 03:25 AM.


Powered by vBulletin Copyright © 2013 vBulletin Solutions, Inc.