ai didi

php - 如何在 View 中打印 sql 计数?

转载 作者:行者123 更新时间:2023-11-29 06:19:59 24 4
gpt4 key购买 nike

我有这个

$noOfcomment = DB::select("SELECT COUNT(comment) as cs FROM comments WHERE placeid='$pid->placeid'"); 

但我不知道如何在 View 中打印结果?

最佳答案

The select method will always return an array of results.

print_r($noOfcomment);

要打印计数:

echo $noOfcomment[0]->cs;

要在 View 中打印结果,您必须传递一个变量:

return View::make('viewName', array('count' => $noOfcomment[0]->cs));

然后在你的 View 中打印结果:

<?php echo $count; ?>

要获取更多有关 Laravel 数据库的详细信息,请查看:

http://laravel.com/docs/4.2/database

要了解更多有关 Laravel 中 View 的详细信息,请查看:

http://laravel.com/docs/4.2/responses

关于php - 如何在 View 中打印 sql 计数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33805056/

24 4 0
文章推荐: mysql - 单表动态返回多个平均值的SQL语句是什么
文章推荐: mysql - 如何使用pem文件完成远程mysqldump?
文章推荐: mysql - 如何找到sql表的最佳索引?
文章推荐: mysql - TimeStamp 列始终为零值
行者123
个人简介

我是一名优秀的程序员,十分优秀!

滴滴打车优惠券免费领取
滴滴打车优惠券
全站热门文章
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com