Quantcast
Channel: CodeIgniter Forums - All Forums
Viewing all articles
Browse latest Browse all 14346

Pagination with search

$
0
0
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');


Viewing all articles
Browse latest Browse all 14346

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>