![](/img/trans.png)
[英]How to fetch and return record with total number of records in codeigniter
[英]How to get total number of record in the query using codeigniter?
这是我的代码
$attendanceDetail = $this->common->getWhere('tbl_attendance', 'date', $allDate);
$total = $attendanceDetail->num_rows();
if($total >0 )
{
echo "record found";
}
else{
echo "Not Found";
}
如何获取查询结果中的记录总数?
尝试以下操作:将此方法放入模型中
public function count_records($table_name) {
return $this->db->count_all($table_name);
}
count_all
是查询构建器类方法,该方法返回表中的记录总数,请参见此处
并在您的控制器方法中使用它,如下所示:
$total_records = $this->your_model->count_records('put_table_name_here');
$attendanceDetail = $this->common->getWhere('tbl_attendance', 'date', $allDate);
$total = count($attendanceDetail);
if($total >0 )
{
echo "record found";
}
else{
echo "Not Found";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.