Pagination problem when search in other of pagination link ? |
[eluser]ilove-ci[/eluser]
Hi, I have some code ///controller function index() { $this->load->library('pagination'); $this->load->model('member_model','member'); if ($this->uri->segment(3) !== FALSE) { $offset = $this->uri->segment(3); } else { $offset='0'; } if($this->input->post('searchterm')) { $session_data = array('search_query'=>$this->input->post('searchterm')); $this->session->set_userdata($session_data); } $config['base_url'] = base_url().'index.php/find/index/'; $config['per_page'] = '10'; $config['total_rows'] = $this->member->count_rows_by_keyword($this->session->userdata('search_query')); $config['first_link'] = 'first'; $config['last_link'] = 'last'; $config['full_tag_open'] = '<p>'; $config['full_tag_close'] = '</p>'; $config['uri_segment'] = '2'; $this->pagination->initialize($config); $data['page_links'] = $this->pagination->create_links(); $data['members'] = $this->member->search($this->session->userdata('search_query'),$offset,$config['per_page'] ); $data['search_query'] = $this->session->userdata('search_query'); $data['rows'] = $config['total_rows']; $this->load->view('find/index',$data); } //Model function search($term,$offset,$num) { //$term = $this->db->escape($term); $data = array(); if($term!='') { $this->db->select('*'); $this->db->like('name',$term); $this->db->orlike('lastname',$term); $this->db->orlike('address',$term); $this->db->orlike('province',$term); $this->db->orlike('part_of_thailand',$term); $this->db->orlike('business_name',$term); $this->db->orlike('old_academy',$term); } //$this->db->orderby('name','asc'); $this->db->limit($num,$offset); $query = $this->db->get('members'); return $query; } ///////////////////////////////////// when I go to page 2 or 3 then search again, the record found but uri not correct ( I think it should redirect to segment 0) What should I do????
[eluser]nikefido[/eluser]
can you show us your correct URI and then what the incorrect URI looks like? Paginated search results are always a pain to deal with because of the problem of persistence. How do you carry over your query for each page? One way is to have queries that are good in URLs (like search/index/id/1 might search where id=1) - These can be used with the pagination class if you do something like this: Code: $config[‘base_url’] = base_url().‘index.php/find/index/’.$this->uri->segment(3).'/'.$this->uri->segment(4); I'm iffy with using sessions to hold complex serialized data such as arrays (mostly because of the hole in my knowledge in that area). If your sessions are being handled in the database, this probably isn't a bad way to go. I like using URLs for search queries because they can be bookmarked.
[eluser]ilove-ci[/eluser]
Url when I search with 40 records and config['per_page']='20' in the next page when I search again the record it found but url look like 'http://www.codeigniter.com/index.php/find/index/10',it should be http://www.codeigniter.com/index.php/find/index/ direct to page one. Thank you very much. |
Welcome Guest, Not a member yet? Register Sign In |