分页不显示在网页上

时间:2013-03-06 10:25:54

标签: php codeigniter pagination

大家好我因为某些原因显示我的分页时出现了一些问题,页面上没有出现分页剂量可以帮助我这里的代码是我的代码:

查看

<div>    


     <table border="1">


      <tr>
         <th>Name</th>
         <th>Second Name</th>
         <th>Phone</th>
         <th>Email</th>
         <th>Answer</th>
         <th>Comment</th>
     </tr>
      <?php foreach ($query as $row): ?> 
     <tr>

         <td><?php echo $row->name; ?></td>
         <td><?php echo $row->second_name; ?></td>
         <td><?php echo $row->phone; ?></td>
         <td><?php echo $row->email; ?></td>
          <td> <?php echo $row->answerA;?>
          <?php echo $row->answerB;?>
          <?php echo $row->answerC;?></td>
         <td><?php echo $row->comment;?><br></td>

     </tr>

      <?php endforeach; ?>

     </table>  
     <?php echo $this->pagination->create_links(); ?>


   </div>

控制器

 <?php

class Result_controller extends CI_Controller{

    function getall(){

   $this->load->model('result_model');
        $data['query'] = $this->result_model->result_getall();
        // print_r($data['query']); die();


        $this->load->library('pagination');

        $config['base_url'] = 'http://localhost/Surva/index.php/result_controller/getall';
        $config['total_rows'] = $this->db->get('tblanswers')->num_rows();
        $config['per_page'] = 1;
        $config['num_links'] = 10;


        $this->pagination->initialize($config);

        $data['records'] = $this->db->get('tblanswers', $config['per_page'], $this->uri->segment(1, 0))->result_array();
        $data['pagination'] = $this->pagination->create_links();
        $this->load->view('result_view', $data);




        }

我使用了codeigniter指南以及我在nettuts上找到的教程,我们将非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

这样做

    $this->load->library('pagination');
    $limit = 10;

    $total = $this->legend_model->get_legend_count($language_id);

    $config['base_url'] = base_url().'legend/index/';
    $config['total_rows'] = $total;
    $config['per_page'] = $limit;
    $config['uri_segment'] = 3;

    $config['first_link'] = '<< First';
    $config['last_link'] = 'Last >>';
    $config['next_link'] = 'Next ' . '&gt;';
    $config['prev_link'] = '&lt;' . ' Previous';
    $config['num_tag_open'] = '<span class="number">';
    $config['num_tag_close'] = '</span>';

    $config['cur_tag_open'] = '<span class="current"><a href="#">';
    $config['cur_tag_close'] = '</a></span>';

    $this->pagination->initialize($config);
    $data['offset'] = $offset;
    $data['legends'] = $this->legend_model->get_legend($language_id, $limit, $offset);

    $this->template->write('title', 'Legend : Manage Legend');
    $this->template->write_view('content', 'legend/index', $data);
    $this->template->render();