PHP Codeigniter计数行 [英] php codeigniter count rows
本文介绍了PHP Codeigniter计数行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Codeigniter的新手,我想对数据库表中的所有行进行计数,但查询未获取确切的总行数。
这是模型
I am new in codeigniter, I want to count all rows from database table but the query dose not retrieve the exact total of rows. Here is Model
public function countRow(){
$query = $this->db->query("SELECT *,count(id) AS num_of_time FROM home");
// print_r($query->result());
return $query->result();
}
这是控制者
public function countTotalrow(){
$data['query'] = $this->home_model->countRow();
}
这是视图
foreach ($num_of_time as $row){
<span><?php print_r($row->id);?></span>
推荐答案
您可以使用帮助函数 $ query-> num_rows()
它返回查询返回的行数。您可以这样使用:
It returns the number of rows returned by the query. You can use like this:
$query = $this->db->query('SELECT * FROM my_table');
echo $query->num_rows();
这篇关于PHP Codeigniter计数行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文