Welcome Guest, Not a member yet? Register   Sign In
Search with $term and pagination
#1

[eluser]the_unforgiven[/eluser]


Having trouble with a search feature on a site i have built with CI but having trouble with pagination and limiting to 20 items per page or something.

My controller i have:
Code:
public function program_search()
          {
      if ($this->input->post('term')){
        $this->front->set('title', 'Search Results');
        $this->front->set('res' ,  $this->wc_search->search($this->input->post('term')));

        $this->load->library('pagination');

        $config['base_url'] = base_url().'/site/program_search_results/';

        $this->db->where('JobRef',$this->input->post('term'));
        $this->db->or_where('WorkType',$this->input->post('term'));
        $this->db->or_where('Parish',$this->input->post('term'));
        $this->db->or_where('Location',$this->input->post('term'));

        $config['total_rows'] = $this->db->count_all_results('wc_program');
        $config['per_page'] = 10;
        $config['num_links'] = 20;
        $config['full_tag_open'] = '<div id="pagination">';
        $config['full_tag_close'] = '</div>';

        $this->pagination->initialize($config);    

        $this->front->buffer('content', 'site/program_search_results');
        $this->front->render();
    }
    else
    {
        $this->front->set('title', 'Program Search');
        $this->front->buffer('content', 'site/program_search');
        $this->front->render();
    }
}
Then in my model I have:
Code:
public function search($term)
        {
    $data = array();
    $this->default_select();
    $this->db->like('JobRef', $term);
    $this->db->or_like('Area', $term);
    $this->db->or_like('Parish', $term);
    $this->db->or_like('WorkType', $term);
    $this->db->or_like('Location', $term);

    $this->default_order_by();
    //$this->db->limit(15);
    $q = $this->db->get('wc_program');
        if ($q->num_rows() > 0)
        {
            foreach ($q->result_array() as $row)
            {
                $data[] = $row;
            }
        }
    $q->free_result();
    return $data;
}

So how do i get the pagination to work based on this code, i dont really want to alter the code already there has the search works fine, i just need it to show 15 records per page for whatever term is searched for.

Any help advise and code examples would be highly appreciated.


Messages In This Thread
Search with $term and pagination - by El Forum - 05-29-2013, 12:11 PM
Search with $term and pagination - by El Forum - 05-29-2013, 05:32 PM
Search with $term and pagination - by El Forum - 05-30-2013, 01:58 AM
Search with $term and pagination - by El Forum - 05-30-2013, 04:13 AM
Search with $term and pagination - by El Forum - 05-30-2013, 04:16 AM
Search with $term and pagination - by El Forum - 05-30-2013, 04:17 AM
Search with $term and pagination - by El Forum - 05-30-2013, 04:24 AM
Search with $term and pagination - by El Forum - 05-30-2013, 04:27 AM
Search with $term and pagination - by El Forum - 05-30-2013, 09:37 AM
Search with $term and pagination - by El Forum - 05-30-2013, 10:15 AM
Search with $term and pagination - by El Forum - 05-30-2013, 10:17 AM
Search with $term and pagination - by El Forum - 06-06-2013, 08:31 AM
Search with $term and pagination - by El Forum - 06-06-2013, 04:55 PM
Search with $term and pagination - by El Forum - 06-07-2013, 01:56 AM



Theme © iAndrew 2016 - Forum software by © MyBB