我有一个 Joomla 1.5 网站。我的网站上有不同“状态”的文章。我想做的是“计数”并显示有多少文章,例如“status = 1”(已过期)或“status = 3”(已阻止)或“status = 2”(有效)等。
这是 PhpMyAdmin 中的状态 - http://awesomescreenshot.com/07a8ijz75
这是我写的,但它总是给我相同的结果 - 1
<?php echo count($this->row->status==1) ?>
我错过了什么吗? 谢谢
最佳答案
使用SQL计数函数。
select count(*) from articles where status = 1;
使用您的数据库!如果您在 PHP 代码中对数据库中的数据进行排序、计数等操作,您做错了。
如果您想要所有状态,请执行以下操作:
select status, count(*) from articles group by status;
关于php "count()"函数和数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11121677/