douduan9129 2014-09-18 03:31
浏览 23

与Codeigniter分页

I'm using Codeigniter..and i'm new to this. What i'm trying to do is to use pagination in my code but the problem is the pagination link is not shown at the bottom.

My Controller:

public function dsbds() 
        {    
             $this->load->library('pagination');
             $this->load->model('admin_model');
             $result_per_page = 1;  // the number of result per page
             $config['base_url'] = base_url() . '/admin/';
             $config['total_rows'] = $this->admin_model->dsbds();
             $config['per_page'] = $result_per_page;
             $this->pagination->initialize($config);

             $datatable = $this->admin_model->dsbds($result_per_page, $this->uri->segment(3));
             $this->load->view('admin/danhsachbds', array(
                'bds' => $datatable,
                'result_per_page' => $result_per_page
            ));


        }

My Model:

public function dsbds($limit, $offset)
        {
        $this->db->limit($limit, $offset);
        $q = $this->db->query("SELECT bds.id, duan.tenduan, loaibds.loai, bds.tieude, phongngu.phongngu, phongtam.phongtam, viewbds.view, huongbds.huong, noithat.noithat, bds.dientich, bds.gia, donvibds.donvi, bds.noidung, duan.slugda, bds.slugbds, bds.datecreate, bds.dateupdate FROM bds LEFT JOIN duan ON duan.id=bds.tenduan LEFT JOIN loaibds ON loaibds.id=bds.loai LEFT JOIN phongngu ON phongngu.id=bds.phongngu LEFT JOIN phongtam ON phongtam.id=bds.phongtam LEFT JOIN viewbds ON viewbds.id=bds.view LEFT JOIN huongbds ON huongbds.id=bds.huong LEFT JOIN noithat ON noithat.id=bds.noithat LEFT JOIN donvibds ON donvibds.id=bds.donvi ORDER BY bds.id DESC");

             if($q->num_rows() > 0)
                 return $q->result();
             return false;
        }

My View:

    <table>

     <tbody>

      <?php foreach($bds as $d) { ?>
        <tr>
        <td><?php echo $d->id; ?></td>
        <td><?php echo $d->tenduan; ?></td>
        <td><?php echo $d->phongngu; ?></td>
        <td><?php echo $d->phongtam; ?></td>
        <td><?php echo $d->dientich; ?></td>
        <td><?php echo $d->noithat; ?></td>
        <td><?php echo $d->gia; ?> <?php echo $d->donvi; ?></td>          
        <td><button type="button" class="btn btn-success btn-sm">Edit</button> </td>
         </tr>
                        <?php } ?>   
  </tbody>
    <?php echo $this->pagination->create_links();  ?>
  </table>

My Error:

Severity: Warning Message: Missing argument 1 for Admin_Model::dsbds(), called in /application/controllers/admin.php on line 231 and defined Filename: models/admin_model.php

Severity: Warning Message: Missing argument 2 for Admin_Model::dsbds(), called in /application/controllers/admin.php on line 231 and defined Filename: models/admin_model.php

A PHP Error was encountered Severity: Notice Message: Undefined variable: limit Filename: models/admin_model.php Line Number: 316

A PHP Error was encountered Severity: Notice Message: Undefined variable: offset Filename: models/admin_model.php Line Number: 316

Fatal error: Unsupported operand types in /code/system/libraries/Pagination.php on line 124

  • 写回答

1条回答 默认 最新

  • douzhongjiu2263 2014-09-18 03:45
    关注

    First of all $result_per_page is not defined in the controller function. You should define it inside the function. Also $this->uri->segment(3) does not seems to be exists in your case. What is the url of page, you are trying. You should count url segments again. Well, i am sure you are testing first page, and it does not has paging segment (3rd) in this case.

    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效