例如:
// GET ALL ROWS
$get_rows = $sql->query("SELECT expire,date_original,date, FROM table");
$gr = $get_rows->fetch_rows;
然后使用结果......
$expired = count($gr->expire == 0);
$active = count($gr->expire == 1);
$reposted = count($gr->date_original != date);
还是那种效果?
答案 0 :(得分:1)
$result = mysqli_query("SELECT expire,date_original,date, FROM table");
while ($gr= mysqli_fetch_object($result)) {
$expired = count($gr->expire == 0);
$active = count($gr->expire == 1);
$reposted = count($gr->date_original != date);
}
答案 1 :(得分:1)
通常这不是一个好主意,特别是如果你有超过一百万条记录。
为了执行count(),您需要浏览每条记录并理解信息。如果你有几行,这没关系,但是当记录变大时,你最好发出正确的计数sql。
你最好写一个这样的SQL:
select SUM(IF(expire == 1, 1, 0)) as expired,
SUM(IF(expire == 0, 1, 0)) as notExpired
from table;
您仍然可以应用条件,但如果您有足够的资源来处理要检索的记录数量,那么请使用上述解决方案,但是当您谈论大量企业数据时,S
答案 2 :(得分:0)
只需使用SQL COUNT
函数
SELECT COUNT(*) as `expired` from `table` WHERE <your_condition>