codeigniter分页中的索引限制

时间:2015-11-18 02:51:43

标签: php mysql codeigniter pagination

抱歉,我希望create table分页能够连接两个表 我试图创建它,当我点击下一步'像这样的错误。

Error Index Limit

控制器中的我的代码

public function index()
{
    $this->load->model('mymodel');
    $this->load->library('pagination');
    $config['base_url'] = base_url().'index.php/admin/page/index/';
    $config['total_rows'] = $this->mymodel->tampil_data()->num_rows();
    $config['per_page'] = 10; 
    $this->pagination->initialize($config); 
    $data['paging']     =$this->pagination->create_links();
    $halaman            =  $this->uri->segment(3);
    $halaman            =$halaman==''?0:$halaman;
    $data['record']     =    $this->mymodel->tampil_data_paging($halaman,$config['per_page']);
    $this->template->load('template','view',$data);
}

和mymodel

    function tampil_data()
    {
        $query= "SELECT b.requestorname,b.checkin,b.checkout,b.company,b.email,b.contactnumber,b.purpose,
        kb.name,kb.checkinvisitor,kb.checkoutvisitor,kb.companyvisitor,kb.position,kb.contactnumbervisitor
                FROM messrequestor as b,messvisitor as kb
                WHERE b.idrequestor=kb.idrequestor";
        return $this->db->query($query);
    }

        function tampil_data_paging($halaman,$batas)
    {
        $query= "SELECT b.requestorname,b.checkin,b.checkout,b.company,b.email,b.contactnumber,b.purpose,
        kb.name,kb.checkinvisitor,kb.checkoutvisitor,kb.companyvisitor,kb.position,kb.contactnumbervisitor
                FROM messrequestor as b,messvisitor as kb
                WHERE b.idrequestor=kb.idrequestor limit $halaman,$batas";
        return $this->db->query($query);
    }

如何解决?

谢谢

2 个答案:

答案 0 :(得分:0)

$config['base_url'] = base_url().'index.php/admin/page/index/';
//then you use this
$halaman =  $this->uri->segment(3);
$halaman =$halaman==''?0:$halaman;

这是将段检索为'index',因此这将放在您的sql中,而这就是错误所在的位置。如果实际值是在那之后你需要得到另一个段,即4

$query= "SELECT b.requestorname,b.checkin,b.checkout,b.company,b.email,b.contactnumber,b.purpose,
    kb.name,kb.checkinvisitor,kb.checkoutvisitor,kb.companyvisitor,kb.position,kb.contactnumbervisitor
            FROM messrequestor as b,messvisitor as kb
            WHERE b.idrequestor=kb.idrequestor limit $halaman,$batas

答案 1 :(得分:0)

public function index()
{
    $this->load->model('mymodel');
    $this->load->library('pagination');
    $config['base_url'] = base_url().'index.php/admin/page/index/';
    $config['total_rows'] = $this->mymodel->tampil_data()->num_rows();
    $config['per_page'] = 10; 
    $this->pagination->initialize($config); 
    $data['paging']     =$this->pagination->create_links();
    $halaman            =  $this->uri->segment(3);
    $halaman            =$halaman==''?0:$halaman;
    $data['record']     =    $this->mymodel->tampil_data_paging($halaman,$config['per_page']);
    $this->template->load('template','view',$data);
}

在此控制器中,您将该段检索为“索引”,因此将其放置在您的sql中,您需要获取其他段