【问题标题】:Pagination in CodeIgniter with join tablesCodeIgniter 中的分页与连接表
【发布时间】:2014-07-31 22:35:31
【问题描述】:

好的,我想用连接表进行分页。我想对两个表的结果进行分页。我的问题是如何将限制和偏移量传递到我的模型中。到目前为止我的代码:

控制器

$this->load->view('includes/nav_com2');

$this->load->model("Membership_model");

$this->load->library('pagination');

$config['base_url']= 'http://localhost/rip/home/comments';
$config['total_rows']= $this->db->get('comments')->num_rows;
$config['per_page']= 2;
$config['num_links']= 5;
$config['uri_segment'] = 3;
$this->pagination->initialize($config);

$data['records'] = $this->Membership_model->get_data($config['per_page'],$this->uri->segment(3));
$this->load->view('comments',$data);

型号:

public function get_data(){

    $query = $this->db->query("SELECT photos.image_min, users.username FROM photos JOIN comments on photos.users_id = comments.user_id JOIN users on users.id = photos.id ");
    return $query;

}

【问题讨论】:

标签: mysql codeigniter


【解决方案1】:
$query = $this->db->query("SELECT * FROM
     anything GROUP BY date DESC LIMIT $num, $offset");

【讨论】:

    【解决方案2】:

    试试下面的代码..

        $this->db->select('photos.image_min, users.username');
        $this->db->from('photos');
        $this->db->join('comments', 'photos.users_id = comments.user');
        $this->db->join('users', 'photos.id = users.id');
        $this->db->limit($num, $offset);
        $method = 'result';
        return $this->db->get()->$method();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-24
      • 2019-06-30
      • 2018-04-26
      • 1970-01-01
      • 2013-10-28
      • 2017-10-06
      • 1970-01-01
      • 2018-05-11
      相关资源
      最近更新 更多