If I use this statement:
$query = "select * from Products where category_description='".$search_dept."' ORDER BY $orderby LIMIT $offset, $rowsPerPage";
I get 3 results returned, which is correct.
If I use this statement:
$query = "select * from Products where material like \"%$trimmed%\" OR ProductName like \"%$trimmed%\" ORDER BY $orderby LIMIT $offset, $rowsPerPage";
I get correct results.
However, if I try to combine them:
$query = "select * from Products where category_description='".$search_dept."' AND material like \"%$trimmed%\" OR ProductName like \"%$trimmed%\" ORDER BY $orderby LIMIT $offset, $rowsPerPage";
I am getting incorrect results. It is returning too many. Any ideas what I’m doing wrong?
I suggest adding parenthesis around the two logical sets of criteria (more importantly the OR section). As it is, you are implicitly trusting order of operations, and I don’t think it’s deciding the way you want it it. Parenthesis should do the trick: