Reputation: 177
I am trying to give facility of pagination and search keyword in one report with Code-igniter Framework.
Below is the Controller code for that Purpose:
$queryString="?start_date=".$values['start_date']."&end_date=".$values['start_date']."&keyword=".$values['keyword']."";
if($this->uri->segment(3)){
$offset=$this->uri->segment(3);
$config['base_url'] = base_url()."reports/mysearch_search/".$offset.$queryString;
}else{
$config['base_url'] = base_url()."reports/mysearch_search/".$queryString;
}
$query = $this->db->query("SELECT * FROM (`dlrReport`) WHERE LEFT(`res_submit_date`,10) >= '".$values['start_date']."' AND LEFT(`res_submit_date`,10) <= '".$values['end_date']."' AND (number LIKE '%".$values['keyword']."%' OR source LIKE '%".$values['keyword']."%')");
$config['total_rows']=$query->num_rows();
$config['per_page'] = 2;
$this->pagination->initialize($config);
$where = array('LEFT(res_submit_date,10) >=' => $values['start_date'],'LEFT(res_submit_date,10) <=' =>$values['end_date']);
$this->db->where($where);
$this->db->where("(number LIKE '%".$values['keyword']."%' OR source LIKE '%".$values['keyword']."%')");
$res = $this->db->get('dlrReport', $config['per_page'], $this->uri->segment(3));
$dlr['details']= $res->result();
$dlr['start_date']=$values['start_date'];
$dlr['end_date']=$values['end_date'];
$dlr['keyword']=$values['keyword'];
$this->load->view('mysearch',$dlr);
Getting Below link in pagination links which is not working:
http://Host/project/reports/mysearch_search/?start_date=2014-01-23&end_date=2014-01-23&keyword=/2
Url i am expecting in pagination links is like:
http://Host/project/reports/mysearch_search/2?start_date=2014-01-23&end_date=2014-01-23&keyword=
How can i will Get right Url for searching Purpose?
Upvotes: 3
Views: 263
Reputation: 5018
Here is nice example from codeignter itself. Codeigniter Pagination check this.
By default codeigniter is expecting the pagination url like this.
http://localhost/project/reports/mysearch_search/2014-01-23/2014-01-23/2
$start_date =$this->uri->segment(5);
$end_date = $this->uri->segment(6);
$keyword = $this->uri->segment(7);
and if you need this kind of url then you have to change the
http://example.com/index.php?c=test&m=page&per_page=20
then you have to change to set this on config file
$config['enable_query_strings'] set to TRUE
Upvotes: 1