Jump to content

searching with and, and or


Ninjakreborn

Recommended Posts

I am having to make a query with and's but also with or's.

See the ones that have to match are category, subcategory, and schoolname.  THen I also want to have like an open source query

$select = "SELECT * FROM $postset WHERE categoryname = '$category' AND subcategoryname = '$subcategory' AND schoolname = '$school' OR itemtitle LIKE '%$search%' OR description LIKE '%$search%';";
See how i need to make sure it stays within that category, subcategory and schoolname, but the other part is selecting based on different criteria.  Is this the right way to go about this??
Link to comment
Share on other sites

$select = "SELECT * FROM $postset WHERE categoryname = '$category' AND subcategoryname = '$subcategory' AND (schoolname = '$school' OR itemtitle LIKE '%$search%' OR description LIKE '%$search%');";


i think that will do the trick because u need all the first thing and any of the following OR fields..


Regards
Liam
Link to comment
Share on other sites

Well sort of, that is on the right track.  I need to search ALL the or fields, and pull results out of whichevers match, but the other's before that, including the school name, HAVE to match 100%.  Then everything else I need it to go through checking each one, and pulling out all the results from them
Link to comment
Share on other sites

$select = "SELECT * FROM $postset WHERE categoryname = '$category' AND subcategoryname = '$subcategory' AND schoolname = '$school' AND (itemtitle LIKE '%$search%' OR description LIKE '%$search%')";

so we check for all the ands and then for either itemtitle like search or description like search

Any good?
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.