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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.