I have the following SQL statement:
mysql_query("SELECT * FROM `friends` WHERE friend1='$username' OR friend2='$username' AND confirmed='1'");
What I’m trying to accomplish is delete from the table select data from the table friends where one of the two fields is equal to your username, and the confirmed field has to equal 1. This doesn’t seem to be working though. What’s the best way to rewrite it?
Try this with your friend clauses in parenthesis:
This will ensure that one of your friend conditions is met. No matter which one matches, it’ll also check the confirmed bit. If neither friend condition matches, the row isn’t part of the resultset.