$result = mysql_query("SELECT * from messages where user='12'");
If (!result)
{
//Do something
}
else
{
mysql_query("UPDATE messages set read='yes' where user='12'");
}
Also see, how to check if mysql query return no result(record not found) using php?
EDIT: Your question is unclear as to what you are asking, but it seems to say how can you do what you want with an if
statement, not do both in one query, which, if that is the case, I do not know what that question means.
EDIT: After thinking, try this,
IF EXISTS (SELECT * from messages where user='12')
THEN
UPDATE messages set read='yes' where user='12'
ELSE
SELECT * from messages where user='12'
(or do an insert)
Cue taken from,
SQL - IF EXISTS UPDATE ELSE INSERT Syntax Error