使用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);https://stackoverflow.com/questions/55484690
复制相似问题