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

[eluser]Thorpe Obazee[/eluser]
I am currently having problem with my code when searching through a keyword. This is currently what I have.
Code:
function search($keyword = FALSE)
    {  
        $keyword = $this->input->xss_clean($this->uri->segment(3));
        
        $this->job_model->keyword = $keyword;
        
        $data['count_result'] = $this->job_model->count_result();
        
        $config['base_url'] = base_url().'index.php/job/search/'.$keyword.'/';
        $config['total_rows'] = $data['count_result'];
        $config['per_page'] = 3;
        
        // initialize pagination class
        $this->pagination->initialize($config);
        
        $offset = (int)$this->uri->segment(4);
        
        $data['posts'] = $this->job_model->search($config['per_page'], $offset);

        $this->load->view('search',$data);

    }

The problem is that when I click on the second page, nothing happens. I am still on the first page results...
#2

[eluser]xwero[/eluser]
What is the job_model->search method code? I think there is the problem to be found.
#3

[eluser]Thorpe Obazee[/eluser]
Code:
function search($limit, $offset = FALSE)
    {
    
        $this->db->select('jobs.id as job_id, jobs.job_name, jobs.job_title as job_title, jobs.job_content, jobs.job_author, jobs.job_posted as job_posted, jobs.cat_id, jobs.job_status, cats.id as cat_id, cats.cat_title');
        $this->db->from('jobs');
        $this->db->join('cats','cats.id = jobs.cat_id');
        
        if (isset($this->keyword))
        {
            $this->db->like('jobs.job_title',$this->keyword);
        }
        
        if ($offset)
        {
            $this->db->limit($limit,$offset);        
        }
        else
        {
            $this->db->limit($limit);        
        }
        
        $this->db->order_by('job_posted');
        
        $query = $this->db->get();
        
        return $query;
    
    }

    function count_result()
    {
    
        $this->db->select('count(jobs.id) as job_count');
        $this->db->from('jobs');
        $this->db->join('cats','cats.id = jobs.cat_id');
        
        if (isset($this->keyword))
        {
            $this->db->like('jobs.job_title',$this->keyword);
        }
        
        $this->db->order_by('job_posted');
        
        $query = $this->db->count_all_results();
        
        return $query;
    
    }

I believe this works since I also use it for another pagination. But then again.. I may be missing something.
#4

[eluser]xwero[/eluser]
That looks ok than my second suspect is the $config['uri_segment'] setting. Try using
Code:
$config['uri_segment'] = 4;
#5

[eluser]Thorpe Obazee[/eluser]
Wow. that worked... Many many thanks....




Theme © iAndrew 2016 - Forum software by © MyBB