A couple things
Your SQL query's parentheses are are off. As it is, you've coupled your FROM and WHERE clauses into the COUNT function. The result is probably a
userto: NULL count: 0.
I think you meant
Code:
SELECT userto, COUNT(*) FROM messages WHERE userto = '$userto'"
which again will only return a single row:
userto: John count: 43
You don't need to use both COUNT and mysql_num_rows here, since the COUNT is aggregating function. If userto is unique, only 1 row will be returned.
Using COUNT only
Code:
$result = mysql_query("SELECT userto, COUNT(*) as count FROM messages WHERE userto = '$userto'");
$row = mysql_fetch_assoc($result));
if ($row['count']>25) {
$msg=$msg."<img src='error.png'> Can't send message<BR>";
$status= "NOTOK";
}
Using mysql_num_rows only
Code:
$messagesNum= mysql_num_rows(mysql_query("SELECT userto FROM messages WHERE userto = '$userto'"));
if ($messagesNum>25) {
$msg=$msg."<img src='error.png'> Can't send message<BR>";
$status= "NOTOK";
}
Last edited by zxcvbnm60 : 04-28-2008 at 10:41 AM.
|