好的,我想用连接表进行分页。我想从两个表中分页结果。我的问题是如何将限制和偏移传递到我的模型中。到目前为止我的代码:
CONTROLLER
$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);
MODEL:
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;
}
答案 0 :(得分:0)
$query = $this->db->query("SELECT * FROM
anything GROUP BY date DESC LIMIT $num, $offset");
答案 1 :(得分:0)
尝试以下代码..
$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();