我有 2 种情况,我在 codeigniter 中获取同一张表的全部数据和总行数,我想知道有没有一种方法可以从中获取总行数、全部数据和 3 个最新插入的记录一码同桌
两种情况的控制器代码如下所示(尽管我使用不同的参数分别为每种情况应用它)
public function dashboard()
{
$data['instant_req'] = $this->admin_model->getreq();
$this->load->view('admin/dashboard',$data);
}
1)从codeigniter中的表中获取全部数据
型号代码
public function getreq()
{
$this->db->where('status','pending');
$query=$this->db->get('instanthire');
return $query->result();
}
查看代码
foreach ($instant_req as $perreq)
{
echo $perreq->fullname;
echo "<br>";
}
2)从codeigniter中的表中获取行数
public function getreq()
{
$this->db->where('status','pending');
$query=$this->db->get('instanthire');
return $query->num_rows();
}
查看代码
echo $instant_req;
原文由 user6390829 发布,翻译遵循 CC BY-SA 4.0 许可协议
您只能制作一个函数,一次为您提供所有数据总行数、全部数据和 3 条最新插入的记录
例如在模型中
在控制器仪表板功能中
在视野中