[eluser]yogesh_CI[/eluser]
Hi everybody,
I have used pagination class of CodeIgniter and it is working fine, but I am not able to implement the pagination class with search option. When i use the search view of at first result it will display the pagination class properly, but when i click on pagination link it will not the values present in search view. How i can implement this please help me, thanks.
My Controller
Code:
function user_view()
{
$this->load->library('pagination');
$this->load->model('user_model');
$config['base_url'] = base_url().'index.php/users/user_view/';
//$config['total_rows'] = $this->db->count_all('Users_T');
$config['total_rows'] = $this->user_model->total_rows();
$config['per_page'] = '4';
$config['full_tag_open'] = '<p>';
$config['full_tag_close'] = '</p>';
$this->pagination->initialize($config);
$pagination = $this->pagination->create_links();
//load the model and get results
$this->load->model('user_model');
$data['results'] = $this->user_model->get_page($config['per_page'],$this->uri->segment(3));
// load the HTML Table Class
$this->load->library('table');
$this->table->set_heading('');
$data['page_header'] = 'User > User View';
$data['option_add'] = 'users/user_add';
$data['hdata'] = 'users/user_add';
$data['tabledata'] = $this->user_model->get_all_users();
$data['no_of_rows'] = $this->user_model->get_row_count();
// load the view
$this->load->view('users/user_view', $data);
}
Model : user_model.php
Code:
function total_rows(){
$search_id = '';
$search_value = '';
$search_address = '';
$search_id = $this->input->post('search_id');
$search_name = $this->input->post('search_name');
$search_address = $this->input->post('search_address');
$this->db->select('*');
$this->db->from('Users_T');
//$query = $this->db->query('SELECT u. * , r.RoleName_VC FROM Users_t u, Role_T r WHERE u.Role_ID = r.Role_ID');
if(isset($search_id) && $search_id !=''){
$this->db->where('User_ID',$search_id);
}else{
if((isset($search_name) && $search_name !='') && (isset($search_address) && $search_address !='')){
$this->db->like('Name_VC', $search_name);
$this->db->or_like('Emailaddress_VC', $search_address);
}else{
if(isset($search_name) && $search_name !=''){
$this->db->like('Name_VC', $search_name);
}else{
if(isset($search_address) && $search_address !=''){
$this->db->like('Emailaddress_VC', $search_address);
}
}
}
}
$query = $this->db->get();
return $query->num_rows();
//return "10";
}
function get_page($num, $offset) {
$search_id = '';
$search_value = '';
$search_address = '';
$search_id = $this->input->post('search_id');
$search_name = $this->input->post('search_name');
$search_address = $this->input->post('search_address');
$stmt = '';
if($offset){
$stmt = $offset." , ".$num;
}else{
$stmt = $num;
}
$stmt_where = '';
if(isset($search_id) && $search_id !=''){
$stmt_where = "and u.User_ID = '".$search_id."'";
}else{
if((isset($search_name) && $search_name !='') && (isset($search_address) && $search_address !='')){
$stmt_where = "and (u.Name_VC like '%".$search_name."%' or u.Emailaddress_VC like '%".$search_address."%')";
}else{
if(isset($search_name) && $search_name !=''){
$stmt_where = "and u.Name_VC like '%".$search_name."%'";
}else{
if(isset($search_address) && $search_address !=''){
$stmt_where = "and u.Emailaddress_VC like '%".$search_address."%'";
}
}
}
}
$sql = "SELECT distinct(u.User_ID), u.Role_ID, Relation_ID, Contact_ID, UserName_VC, Password_VC, Name_VC, Status_IN, Emailaddress_VC, r.RoleName_VC FROM Users_t u, Role_T r WHERE u.Role_ID = r.Role_ID ".$stmt_where." limit ". $stmt;
//echo $sql;
$query = $this->db->query($sql);
return $query->result_array();
}
}
?>
View : user_view.php
Code:
<?
foreach($results as $result){
<tr>
<td class='td_view' align='left'>
<?=$this->site_sentry->DispID("U ",$result['User_ID'])?>
</td><td class='td_view' align='left'><?php echo $result['UserName_VC']; ?></td>
<td class='td_view' align='left'><?php echo $result['Name_VC']; ?></td>
<td class='td_view' align='left'><?php echo $result['Emailaddress_VC']; ?></td>
<td class='td_view' align='left'><?php echo $result['RoleName_VC']; ?></td>
</tr>
<?
}
?>