使用Codeigntier 3
我试图将我的数据库内容限制在5个帖子上。现在我的预测是正确的,但我不知道如何将这个数字限制在5。
我在网上找到的大部分东西都是代码点火器2的。
控制器
public function index(){
$data['Sideposts'] = $this->Blog_Model->get_bposts();模型
public function get_bposts($slug = FALSE){
if($slug === FALSE){
$this->db->order_by('date','DESC');
$query = $this->db->get('blogposts');
return $query->result_array();
}视图代码
<?php foreach($Sideposts as $Sidepost):{ ?>
<ul style="list-none;">
<?php echo $Sidepost['title']; ?>
</ul>
<?php }endforeach; ?>发布于 2019-04-03 01:32:17
public function get_bposts($slug = FALSE,$lmt=0){
if($slug === FALSE){
$this->db->order_by('date','DESC');
if($lmt>0)
{
$query = $this->db->get('blogposts',$lmt);
} else {
$query = $this->db->get('blogposts');
}
return $query->result_array();
}请按以下方式使用:
$data['Sideposts'] = $this->Blog_Model->get_bposts(FALSE,5);发布于 2019-04-02 23:11:41
只需在模型php中替换这个
$query = $this->db->get('blogposts');通过
$query = $this->db->get('blogposts', 5);发布于 2019-04-02 23:31:54
使用camao的答案,但是在get_bposts()函数中添加一个参数来指定您想要得到多少。
https://stackoverflow.com/questions/55484690
复制相似问题