如何在codeigniter控制器中使用限制

时间:2017-08-02 11:17:56

标签: php ajax pagination codeigniter-3

我正在进行ajax滚动分页。控制器如下所示

value={this.state.encrypted}

$ count变量包含5个数据,我想为第一页发送3,为第二页发送剩余。怎么做。

1 个答案:

答案 0 :(得分:1)

试试这个......

<强>型号:

function getcourses($tutorId, $limit = null) {
    $this->db->select('*');
    $this->db->from('courses');
    $this->db->where("tutorId", $tutorId);
    //$this->db->order_by("name", "asc");

    if($limit!=''){
       $this->db->limit($limit);
    }
    $query  = $this->db->get();

    $courses = array();
    foreach ($query->result() as $row)
        array_push($courses, $row);

    return $courses;     
}

<强>控制器:

public function index(){
    $tutorId = $this->session->userdata('cp_userid');
    $limit = 3;
    $categorycourses = $this->Usermodel->getcourses($tutorId, $limit);
    //$categorycourses=$this->Usermodel->getcourses($tutorId);

    $count = $categorycourses->num_rows();

    $data['details'] = $categorycourses;      

    $this->load->view("user/pagination_view", $data, true);
}