I have this line in my sql query:
WHERE client = $id
AND (isinvoiced = 0) OR (isinvoiced = 1 and isrecurring = 1)
which gets more results than I am expecting. However, if I write it like this:
WHERE client = $id
AND (isinvoiced = 0) OR (isinvoiced = 1 and isrecurring = 1 and client = $id)
then it gets me the results I wanted, but this is the best way to write this? I just don’t want run into any more issues with this code.
You need one more set of
()around the entireANDclause. This states thatclient = $idMUST be true, and either of the other conditions must also me true =isinvoiced = 0OR the combination ofisinvoiced = 1 and isrecurring = 1.