Forum Moderators: coopster
$query = mysql_query("SELECT * FROM table WHERE description LIKE '%$search%' OR name LIKE '%$search%' AND pending != 'true'");
and then it displays the results to the user. I'm having problems with the pending part for some reason it's getting all the rows and not getting rid of the ones the are equal to true. I'm not quite sure what to do so I'm asking.
Thanks in advance!
SELECT * FROM table WHERE (description LIKE '%$search%' OR name LIKE '%$search%') AND pending <> 'true'";
Edit: Ooops, guess I was wrong about the not equal, probably more has to do with the ()'s:
[dev.mysql.com...]
When you put single quotes around the word true.... 'true' you are passing it a string.
If it is boolean you don't want to look for the string 'true' you want to use either true or false... no quotes or use 0 and 1
When using booleans and the words "true" or "false" you can use the keyword 'is' in your statement.
select ..... and pending is true
or
select ..... and pending is not true
I'm having problems with the pending part for some reason it's getting all the rows and not getting rid of the ones the are equal to true.
Your problem is most likely in the or:
$query = mysql_query("SELECT * FROM table WHERE description LIKE '%$search%' OR name LIKE '%$search%' AND pending != 'true'");
The "and" will only apply the pending conditional to the "name like ..." in this context. it will select all records where "description like...." Or is a slippery one this way, try using parentheses:
$query = mysql_query("SELECT * FROM table WHERE (description LIKE '%$search%' OR name LIKE '%$search%') AND pending != true");
This way the "and" applies to both of the "or" conditions. Second, it's probably easier to read if "pending" is tested for false (unless it can maintain other values?)
$query = mysql_query("SELECT * FROM table WHERE (description LIKE '%$search%' OR name LIKE '%$search%') AND pending = false");
I'm not sure of the accuracy of the statement about quotes; in my experience it hasn't made any difference whether it's quoted or not, only that for text and decimal fields it must be quoted, for int, tinyint, and boolean fields it's optional.