Welcome Guest, Not a member yet? Register   Sign In
Pagination with search
#1

I've had some issues searching with pagination. I've resolved it with the following code, but I feel I'm basically doing something fundamentally wrong. Could someone check and give me feedback about what this could be? Thanks.

PHP Code:
public function read()
{
 
 $this->load->library('pagination');
 
 $offset 0;
 
 $config['base_url'] = base_url("language/read");
 
 $config['per_page'] = 3// sql query LIMIT number
 
 $offset = ( $this->uri->segment(3) ? $this->uri->segment(3) : );

 
 // set search
 
 if$this->input->post('search') || $this->input->get('search') ) {
 
   $search = ( $this->input->post('search') ? $this->input->post('search') : $this->input->get('search') );
 
 }
 
 else {
 
   // user has hit return in an empty input field, or has clicked a query link with no property value
 
   $search NULL;
 
 }

 
 $config['suffix'] = "?search=$search"// attaches a query onto $this->uri->segment(3), aka $offset

 
 // !issue fix! user searches while offset is out of range of search result
 
 if$offset != && $this->input->post('search') ){
 
   redirect("language/read/0?search=$search");
 
 }
 
 // !issue fix! user searches while no GET query is in URL
 
 if$offset != && $this->input->get('search') === NULL ){
 
   redirect("language/read/0?search=$search");
 
 }

 
 $this->data['languages'] = $this->language_model->get_languages_pagnation($config['per_page'], $offset$search);
 
 $config['total_rows'] = $this->db->query("SELECT id FROM languages WHERE title LIKE '%$search%'")->num_rows();
 
 $config['first_url'] = "0?search=$search"// explicitly set this to the first link

 
 $this->pagination->initialize($config);
 
 $this->data['pagination'] = $this->pagination->create_links();
 
 $this->render('language');

Reply


Messages In This Thread
Pagination with search - by n2fole00 - 02-20-2017, 02:00 AM
RE: Pagination with search - by ignitedcms - 02-23-2017, 02:57 PM
RE: Pagination with search - by nkhan - 10-19-2017, 08:57 PM
RE: Pagination with search - by n2fole00 - 02-24-2017, 12:09 AM
RE: Pagination with search - by albertleao - 02-24-2017, 12:32 AM
RE: Pagination with search - by ignitedcms - 02-24-2017, 02:40 AM
RE: Pagination with search - by RWCH - 10-13-2017, 07:09 AM
RE: Pagination with search - by Wouter60 - 02-24-2017, 04:34 AM
RE: Pagination with search - by PaulD - 10-13-2017, 11:22 AM



Theme © iAndrew 2016 - Forum software by © MyBB