分页不改变页面 [英] pagination does not change page

查看:110
本文介绍了分页不改变页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的网站工作分页,其中我显示数据从数据库中的两个表的数据我有分页在我的页面,但它不表现为它的行为,它表示不改变页面。目前我有16个记录显示在网页上,并设置了 $ config ['per_page'] = 1; 分页栏最多16,但它不能翻转通过页面所有的记录都显示在页面上。任何帮助将在这里感谢我的代码:

I am working on pagination for my website where i am displaying data from two tables on a database i have pagination in my page but it dose not behave as it suppose to behave it dose not change pages. currently i have 16 records displaying on the web page and have set $config['per_page'] = 1; the pagination bar goes up to 16 but it dose not flip through the pages all the records are displayed on the page. any help will be appreciated here is my code :

控制器

 <?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, credentials')->num_rows();
        $config['per_page'] = 1;
        $config['num_links'] = 10;


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

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




        }


}

?>

查看

   <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 if (isset($pagination))
      {
       echo $pagination;
      // echo "<pre>"; var_dump($query);
       } ?>




strong>

model

function result_getall(){

   return $this->db->select('tblanswers.*,credentials.*')
                         ->from('tblanswers, credentials')
                         ->get()
                         ->result_object();


推荐答案

查询不会神奇地知道你只想要x记录数。 Codeigniter将显示从模型中提供的任何内容。

The query doesn't magically know you only want x number of records. Codeigniter is going to display whatever you feed it from the model.

function getall(){

        $this->load->model('result_model');
        // 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, credentials')->num_rows();
        $config['per_page'] = 1;
        $config['num_links'] = 10;
        $config['uri_segment'] = 3; //guessing here, but this is where the uri segment you use to change pages goes.
        if($this->uri->segment('3')) {
        $offest = $this->uri->segment('3');
        } else {
        $offest = 0;
        }
        $data['query'] = $this->result_model->result_getall($config['per_page'],$offset);


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

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




        }



Model:

function result_getall($limit=0,$offset=0){

   if($limit != 0)
   {
   return $this->db->select('tblanswers.*,credentials.*')
                         ->from('tblanswers, credentials')
                         ->limit($limit, $offset)
                         ->get()
                         ->result_object();
   } else {
   return $this->db->select('tblanswers.*,credentials.*')
                         ->from('tblanswers, credentials')
                         ->get()
                         ->result_object();
   }

注意在控制器中我将偏移量和每页传递给模型,然后使用它们限制模型本身的返回。

Notice in the controller I'm passing the offset and the per page to the model, then using them to limit the returns in the model itself.

这篇关于分页不改变页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆