Im trying to count rows in a table. Currently im using this:
$sql = "SELECT COUNT(*)
FROM `friends`
WHERE `user1`='".$user1."'
AND `user2`='".$user2."'
AND `valid`=0
UNION
SELECT COUNT(*)
FROM `friends`
WHERE `user1`='".$user2."'
AND `user2`='".$user1."'
AND `valid`=0";
As you see, user1
can be both $user1
AND $user2
. but it does not count the rows after the UNION
, it only does the first query before UNION
so im ending up with 0 when i actually should be counting 1 row.
How do I solve this?