Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to implement search and pagination in CodeIgniter 2.1's database API?
    primarykey
    data
    text
    <p>I am having trouble with a search feature on a site I built with Codeigniter 2.1. Specifically, I am having trouble with pagination and limiting to 15 items per page.</p> <p>My controller:</p> <pre><code> public function program_search() { if ($this-&gt;input-&gt;post('term')){ $this-&gt;front-&gt;set('title', 'Search Results'); $this-&gt;front-&gt;set('res' , $this-&gt;wc_search-&gt;search($this-&gt;input-&gt;post('term'))); $this-&gt;load-&gt;library('pagination'); $config['base_url'] = base_url().'/site/program_search_results/'; $this-&gt;db-&gt;where('JobRef',$this-&gt;input-&gt;post('term')); $this-&gt;db-&gt;or_where('WorkType',$this-&gt;input-&gt;post('term')); $this-&gt;db-&gt;or_where('Parish',$this-&gt;input-&gt;post('term')); $this-&gt;db-&gt;or_where('Location',$this-&gt;input-&gt;post('term')); $config['total_rows'] = $this-&gt;db-&gt;count_all_results('wc_program'); $config['per_page'] = 10; $config['num_links'] = 20; $config['full_tag_open'] = '&lt;div id="pagination"&gt;'; $config['full_tag_close'] = '&lt;/div&gt;'; $this-&gt;pagination-&gt;initialize($config); $this-&gt;front-&gt;buffer('content', 'site/program_search_results'); $this-&gt;front-&gt;render(); } else { $this-&gt;front-&gt;set('title', 'Program Search'); $this-&gt;front-&gt;buffer('content', 'site/program_search'); $this-&gt;front-&gt;render(); } } </code></pre> <p>Then in my model I have:</p> <pre><code> public function search($term) { $data = array(); $this-&gt;default_select(); $this-&gt;db-&gt;like('JobRef', $term); $this-&gt;db-&gt;or_like('Area', $term); $this-&gt;db-&gt;or_like('Parish', $term); $this-&gt;db-&gt;or_like('WorkType', $term); $this-&gt;db-&gt;or_like('Location', $term); $this-&gt;default_order_by(); //$this-&gt;db-&gt;limit(15); $q = $this-&gt;db-&gt;get('wc_program'); if ($q-&gt;num_rows() &gt; 0) { foreach ($q-&gt;result_array() as $row) { $data[] = $row; } } $q-&gt;free_result(); return $data; } </code></pre> <p>How do I get the pagination to work based on this code? I don't really want to alter the code already there as the search works fine. I just need it to show 15 records per page for whatever term is searched for.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload