php – 从codeigniter中的数据库中获取数据
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php – 从codeigniter中的数据库中获取数据,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1549字,纯文字阅读大概需要3分钟。
内容图文
![php – 从codeigniter中的数据库中获取数据](/upload/InfoBanner/zyjiaocheng/889/c1303cf3770d407bb9deb0fe8521b605.jpg)
我有2个案例,我在codeigniter中获取整个数据和同一个表的总行数,我想知道有一种方法可以从中获取总行数,整个数据和3个最新插入的记录同一个表通过一个代码
Controller code for both cases is as given below (although i am applying it for each case seperately with different parameters)
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;
解决方法:
您只能使用一个函数同时为所有数据提供总行数,整数数据和3个最新插入记录
例如在模型中
public function getreq()
{
$this->db->where('status','pending');
$query=$this->db->get('instanthire');
$result=$query->result();
$num_rows=$query->num_rows();
$last_three_record=array_slice($result,-3,3,true);
return array("all_data"=>$result,"num_rows"=>$num_rows,"last_three"=>$last_three_record);
}
在控制器仪表板功能中
public function dashboard()
{
$result = $this->admin_model->getreq();
$this->load->view('admin/dashboard',$result);
}
在视野中
foreach ($all_data as $perreq)
{
echo $perreq->fullname;
echo "<br>";
}
//latest three record
foreach ($last_three as $perreq)
{
echo $perreq->fullname;
echo "<br>";
}
//total count
echo $num_rows;
内容总结
以上是互联网集市为您收集整理的php – 从codeigniter中的数据库中获取数据全部内容,希望文章能够帮你解决php – 从codeigniter中的数据库中获取数据所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。