Jump to content

SQL Query Syntax


wardo

Recommended Posts

I have the follwoing query that returns the results from a database if any of the search fields (department,name,title,color, classification) are filled in:

[code]$sql = "SELECT name, title, id,reviewdate,date FROM upload WHERE (department = '$listname' OR name LIKE '%$name%' OR title LIKE '%$name%' OR colour LIKE '%$colour%' OR classification LIKE '%$classification%') ORDER by title asc";[/code]

This works fine but how do I return the results if someone searches, for example, for a specifit name within a specific department or a name with a specific classification etc.

So basically, I need to be able to return the results if someone enters information into just one search criteria and also if they enter data into multiple search criteria.

Thanks for your help.
Link to comment
https://forums.phpfreaks.com/topic/17855-sql-query-syntax/
Share on other sites

I have tried simplifying the query and using ANDs but it does not work how I want. I now have:

$sql = "SELECT name, title, id,reviewdate,date FROM upload WHERE (department = '$listname' AND name LIKE '%$name%') OR (department = '$listname' OR name LIKE '%$name%')ORDER by title asc";

This gives the same results as before. Is there a way to modify the statement to do what I need or should I use php if statements to determine which sql statement to run under different circumstances?

Thanks.
Link to comment
https://forums.phpfreaks.com/topic/17855-sql-query-syntax/#findComment-76723
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.