duanpi2033 2015-11-18 02:51
浏览 46
已采纳

codeigniter分页中的索引限制

Sorry, i want the create table pagination to join two tables i've try to created it and when i click 'next' there's error like this.

Error Index Limit

My Code in controller

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);
}

and 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);
    }

how to solve it?

Thank You

  • 写回答

2条回答 默认 最新

  • dpz7935 2016-02-28 14:35
    关注
    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);
    }
    

    in this controller you retrieving the segment as 'index' so this is being placed in your sql, you need to get other segment

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题