gpt4 book ai didi

php - 计算 MySQL 中的特定行数

转载 作者:行者123 更新时间:2023-11-29 13:55:42 25 4
gpt4 key购买 nike

如果我想计算数据库中的某一特定行(未读),我应该如何继续执行此 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传递变量时,并使用 PDOMySQLi -this article将帮助您决定哪个。

关于php - 计算 MySQL 中的特定行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15905760/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com