php - 获取其他表中的新闻总数

标签 php mysql smarty

我在从另一个表获取新的总数时遇到问题,我使用下面的代码:

$news_cat = array(); 
$news_cat = DB::query("select * from news_cat order by id");

foreach($news_cat as $cc){
    DB::query("select news_id from info_news where cat_id=%i",$cc['id']);
    $news_cat['all_news_in_cat'] = DB::count();

}
$smarty->assign('news_cat', $news_cat);
$smarty->display("blog.tpl");

我要打印的是 tpl 文件中的 ( all_news_in_cat )

问候, 阿米尔

最佳答案

你可以稍微改变一下你的SQL。试试这个:

SELECT cat_id, count(news_id) from info_news group by cat_id

应该在一行中返回所有内容

关于php - 获取其他表中的新闻总数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53263944/

相关文章:

javascript - 表单输入显示在下一页

mysql - 按一列分组并有条件地计算另一列 - Mysql

php - Smarty::$_tpl_vars - 未定义属性 - Smarty 3 中支持 _tpl_vars

php - 如何在 PHP 中回显或打印数组?

php - 在 Web 开发 MVC 模式中,将大量 jQuery 代码放置在哪里?

php - 将多个文件上传到 FTP 并将文件的 HTTP 链接上传到 MySQL 数据库

php - 网页顶部的空白区域

mysql - 临时表不存在错误

mysql - CAP_FIRST 函数给出语法错误

php - 聪明人/PHP : Why is it not possible to use two foreach loops in one table with Smarty?