我希望使用分页在每个页面上显示7个结果,但我只在第7页上显示,然后当我点击下一页时,它不会显示任何结果。
控制器
function display($offset=0)
{
$limit=7;
$select = $this->input->post('select');
$name = $this->input->post('name');
if($select=='none')
{
echo '<script>alert("please Select college");</script>';
$this->load->library('user_agent');
$page_url=$this->agent->referrer();
redirect($page_url,'refresh');
}
else
{
$result['numOfRows']=$this->getmodel2->countRows();
$this->load->library('pagination'); #2
$this->load->library('table');
$config=array(
'base_url'=> site_url('Verify3/display/?name='.$name),
'total_rows'=> $result['numOfRows'][0]['count'],
'per_page'=>$limit,
'page_query_string' => TRUE,
'num_links'=>2
);
$result['j']=$this->getmodel2->getSearchbook($limit,$offset,$name,$select); #3
$this->pagination->initialize($config); #4
$result['pagination']=$this->pagination->create_links(); #5
$this->load->view('imageview3',$result);
}
}
模型
function getSearchBook($limit,$offset,$name,$select) {
$query="Select * from home where ownerid='$name' and select='$select limit $limit offset $offset";
$result_query= $this->db->query($query);
}
答案 0 :(得分:1)
您可以使用会话来存储输入数据并在查询中发送会话数据。
if ($name!=NULL&&$select!=NULL) {
$session_data = $this->session->userdata('search_data');
$session_data['search'] = $name;
$session_data['search'] = $select;
$this->session->set_userdata('search_data', $session_data);
}
$result['j']=$this->getmodel2->getSearchbook($limit,$offset,$this->session->userdata['search_data']['search'],$this->session->userdata['search_data']['select']);