如果我想计算数据库中的某一特定行(未读
),我应该如何继续执行此 MySQL 查询?到目前为止,它计算了整个表。
$result_notifications = mysql_query("select count(1) FROM bhost_notifications where taker_id='$user_info[u_id]'");
$row_notifications = mysql_fetch_array($result_notifications);
$total_notifications = $row_notifications[0];
最佳答案
您需要为该列指定别名。
SELECT COUNT(1) AS count ...
然后您将调用$row_followers[count]
。请注意,mysql_
函数已被弃用。了解 prepared statements传递变量时,并使用 PDO或MySQLi -this article将帮助您决定哪个。
关于php - 计算 MySQL 中的特定行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15905760/