2011-11-23 94 views
0

我想根据用户的查询显示来自mysql数据库的信息。我有一个表单,在用户提交数据后,它会发送到我在下面发布的控制器,然后发送到显示用户所需信息的视图文件。Codeigniter的分页不起作用

到目前为止,我对此很满意,但问题与分页创建。目前我有八行数据显示在我的数据库中,因此为了检查分页是否正常运行,我将$ config ['per_page']的值设置为5(请在下面检查)。现在当我点击下一个按钮时,它不显示任何数据。

我认为问题在于,当我点击“下一步”按钮时,它再次进入控制器,但这次控制器没有获得用户首先发布的值。

请你帮我一下吗?

预先感谢:)

我的控制器:

function show(){ 

      $batchid=$this->input->post('batchid'); 
      $daterange1=$this->input->post('daterange1'); 
      $daterange2=$this->input->post('daterange2'); 



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

        $config['base_url'] = base_url().'markslist/show'; 

        $this->db->select('*'); 
         $this->db->from('marks'); 
         $this->db->where('examdate', $daterange1); 
         $this->db->where('examdate', $daterange2); 

         $this->db->join('student', 'marks.studentid = student.studentid'); 
         $this->db->where('batchid', $batchid); 
         $this->db->order_by('batchid','DESC'); 
         $query = $this->db->get(''); 
         $numrows=$query->num_rows(); 

        $config['total_rows'] = $numrows; 
        $config['per_page'] = 5; 
        $config['num_links'] = 20; 
        $config['full_tag_open'] = '<div class="pagination" align="center">'; 
        $config['full_tag_close'] = '</div>'; 

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


      // To get the subject lists 
      $this->load->model('mod_markslist'); 
      $data['records']= $this->mod_markslist->listmarks($batchid,$daterange1,$daterange2,$config['per_page'],$this->uri->segment(3)); 



      $data['main_content']='view_markslist'; 
      $this->load->view('includes/template',$data); 

    } 

回答

1

我会复制最初发布的数据会话:

if($this->input->post()){ 
    $this->session->set_userdata('batchid', $this->input->post('batchid')); 
    $batchid = $this->input->post('batchid'); 
    /* similar for the other posted fields */ 
} 
else{ 
    $batchid = $this->session->userdata('batchid'); 
    /* similar for other fields now in session */ 
} 
/* load pagination library etc */ 

最好也做一个检查,如果该信息虽然可以在会议中使用。

+0

谢谢Mudshark –