我正在尝试从我的表 ptb_messages 中获取用户拥有的新消息的数量,其中“read”设置为“0”
有人可以告诉我哪里出错了。
我的表如下所示:
id | from_user_id | to_user_id | subject | content | date_sent | read
1 2 4 hello hello 2012-04-13 0
我正在使用此功能来尝试显示用户拥有的未读消息的数量。
function check_new_messages() {
global $connection;
global $_SESSION;
$query = "SELECT COUNT('read') FROM ptb_messages WHERE to_user_id =".$_SESSION['user_id']." AND ('read)'='0'";
$check_new_messages_set = mysql_query($query, $connection);
confirm_query($check_new_messages_set);
return $check_new_messages_set;
}
<?php
$check_new_messages_set = check_new_messages();
while ($new = mysql_fetch_array($check_new_messages_set)) {
echo "There are ". $new['COUNT(read)'] ." items.";
}
?>