11-11-2010, 09:38 PM
[eluser]CI_Newb[/eluser]
Trying to get pagination working properly on my search form but having issues getting the total_rows.
I need to get the total_rows from the query rather than from entire database.
Model
Controller
Displaying in view
How do I get the total number of rows from
To show for
Trying to get pagination working properly on my search form but having issues getting the total_rows.
I need to get the total_rows from the query rather than from entire database.
Model
Code:
function admin_search($num, $offset)
{
$start_date = $this->input->post('startDate');
$end_date = $this->input->post('endDate');
$username = $this->input->post('username');
$dateRange = "submit_date BETWEEN '$start_date' and '$end_date'";
$this->db->where($dateRange, NULL);
$this->db->like('username', $username);
$data = $this->db->get('data', $num, $offset);
if($data->num_rows() > 0) {
return $data;
}
}
Controller
Code:
function admin_results()
{
$this->load->library('pagination');
$config['base_url'] = base_url().'/search/admin_results/';
$config['total_rows'] = $this->db->count_all('data');
$config['per_page'] = '100';
$config['num_links'] = 3;
$config['full_tag_open'] = '<p>';
$config['full_tag_close'] = '</p>';
$this->pagination->initialize($config);
$data['users'] = $this->menus->agents_menu();
$data['search'] = $this->search_model->admin_search($config['per_page'],$this->uri->segment(3));
$this->load->view('content/header');
$this->load->view('admin/admin_search_view', $data);
$this->load->view('content/footer');
}
Displaying in view
Code:
echo $this->pagination->create_links();
How do I get the total number of rows from
Code:
$data['search'] = $this->search_model->admin_search($config['per_page'],$this->uri->segment(3));
To show for
Code:
$config['total_rows'] = $this->db->count_all('data');