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
https://forums.phpfreaks.com/topic/21682-searching-with-and-and-or/
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
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
$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?

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.