Welcome Guest, Not a member yet? Register   Sign In
having problems paganating my search [Updated] {sloved answer inside}
#1

[eluser]R_Nelson[/eluser]
I have a list of over 7000 songs the index function shows all of them with pagination the search will show the first 20 but when you go to the 2nd page it goes to the normal 2nd page from index.

Updated : what i'm am trying to do is use the same view page do display the search and the full list but what is happening is i'm losing the search when i try to go to a 2nd page with pagination not sure how to fix it.

Code:
function index()
    {
        $this->load->library('pagination');
        $this->load->library('table');
        
        $this->table->set_heading('', 'Song Name', 'Artist');
        
        $config['base_url'] = 'http://whitetigerdj.com/karaoke/index/';
        $config['total_rows'] = $this->db->get('karaoke')->num_rows();
        $config['per_page'] = 20;
        $config['num_links'] = 10;
        $config['full_tag_open'] = '<div id="pagination">';
        $config['full_tag_close'] = '</div>';        
        $this->pagination->initialize($config);
        $str = $config['total_rows'];
        $this->load->model('Right_model');
        $data['right'] = $this->Right_model->show_right();            
        $data['query'] = '';
        $data['songs'] = $this->_limitchars($str);
        $data['records'] = $this->db->get('karaoke', $config['per_page'], $this->uri->segment(3));    
        $data['title'] = 'Karaoke List';    
        $data['discription'] = '';
        $data['keyword'] = '';
        $data['main_content'] = 'karaoke/karaoke_list';
        $this->load->view('includes/template', $data);
    }
    
    function search()
    {
        $this->load->library('pagination');
        $this->load->library('table');        
        $this->table->set_heading('', 'Song Name', 'Artist');        
        $config['base_url'] = 'http://whitetigerdj.com/karaoke/search/';
        $config['per_page'] = 20;
        $query = $this->input->post('query');
        $data['query'] = $query;
        $data['records'] = $this->db->or_like('song_name',$query)->or_like('artist',$query)->get('karaoke',$config['per_page'], $this->uri->segment(3));
        $config['total_rows'] = $this->db->or_like('song_name',$query)->or_like('artist',$query)->get('karaoke')->num_rows();
        $data['rows'] = $config['total_rows'];
        
        $config['num_links'] = 10;
        $config['full_tag_open'] = '<div id="pagination">';
        $config['full_tag_close'] = '</div>';        
        $this->pagination->initialize($config);
        $str = $this->db->get('karaoke')->num_rows();
        
        $this->load->model('Right_model');
        $data['right'] = $this->Right_model->show_right();
        
        $data['songs'] = $this->_limitchars($str);    
        
        $data['title'] = 'Karaoke List';    
        $data['discription'] = '';
        $data['keyword'] = '';
        $data['main_content'] = 'karaoke/karaoke_list';
        $this->load->view('includes/template', $data);
        
    }
#2

[eluser]R_Nelson[/eluser]
I cant believe it took me this long to find this i should make a video just to make it easier for the next guy! the Bold text is what i added

Code:
function search()
    {
        $query = $this->input->post('query');

Code:
if(strlen($query) > 0){
           $this->session->set_userdata('search',$query);
        }        
        $query = $this->session->userdata('search');
Code:
$search = $this->db->or_like('song_name',$query)->or_like('artist',$query)->get('karaoke','20', $this->uri->segment(3));    
        $count = $this->db->or_like('song_name',$query)->or_like('artist',$query)->get('karaoke')->num_rows();    
        
        $this->load->library('pagination');
        $this->load->library('table');        
        $this->table->set_heading('', 'Song Name', 'Artist');        
        $config['base_url'] = 'http://whitetigerdj.com/karaoke/search/';
        $config['total_rows'] = 28;
        $config['per_page'] = 20;
        $config['num_links'] = 10;
        $config['full_tag_open'] = '<div id="pagination">';
        $config['full_tag_close'] = '</div>';        
        $this->pagination->initialize($config);
        $str = $this->db->get('karaoke')->num_rows();
        $this->load->model('Right_model');
        $data['right'] = $this->Right_model->show_right();        
        $data['songs'] = $this->_limitchars($str);
        $data['records'] = $this->db->or_like('song_name',$query)->or_like('artist',$query)->get('karaoke','20', $this->uri->segment(3));
        $data['title'] = 'Karaoke List';    
        $data['discription'] = '';
        $data['keyword'] = '';
        $data['main_content'] = 'karaoke/karaoke_list';
        $this->load->view('includes/template', $data);
        
    }




Theme © iAndrew 2016 - Forum software by © MyBB