[eluser]Unknown[/eluser]
Hi everyone I am having some difficulty implementing pagination to a view where I am searching for data using like + or_like.
I need some help getting the count of my queried data and passing it to the model.
My search function works perfectly but I can't return the count to my pagination config.
How can I get the count of rows to where $config['per_page']. Be patient with me I'm still learning and get easily lost.
Desperately need help:
Controller:
Code:
// load pagination class
$config['base_url'] = base_url().'/search'.$this->uri->segment(2).'/index/';
$config['total_rows'] = $this->Search_model->search(strtolower($this->uri->segment(2)));
$config['per_page'] = '3';
$config['full_tag_open'] = '<div id="pagination">';
$config['full_tag_close'] = '</div>';
$this->pagination->initialize($config);
$limit = $config['per_page'];
$offset = $this->uri->segment(4);
if($this->uri->segment(2)){
$this->load->model('Search_model');
$viewdata['search_results'] = $this->Search_model->search(strtolower($this->uri->segment(2)),$limit,$offset);
}
Model:
Code:
function search($searchquery, $limit, $offset) {
$this->db->from('content');
$this->db->like('title', $searchquery);
$this->db->or_like('content', $searchquery);
$query = $this->db->limit($limit, $offset)->get();
$results = Array();
foreach ($query->result() as $row) {
$results[] = Array(
'title' => '<a href="' . base_url() . $row->anchor_url . ' ">' . strip_tags($row->title) . '</a>',
'link' => base_url() . $row->anchor_url,
'text' => str_ireplace($searchquery, '<b>' . $searchquery . '</b>', strip_tags(neatest_trim($row->content,220,$searchquery,120,120)))
);
}
return $results;