[eluser]xico[/eluser]
Code:
[quote]$data['siteTitle'] = 'My Test Project';
$data['results'] = $this->usermodel->get_all();
$data['totalRecords'] = $this->usermodel->countTotal();
$data['pagingStr'] = $this->usermodel->paging($data['totalRecords']);
if($data['totalRecords'] < 1) {
$data['messageString'] = 'Sorry no records found!';
} else {
$data['messageString'] = '';
}
if (is_array($_GET) && (count($_GET) > 0))
{
$data['sn'] = floor((10 * $this->usermodel->page)+1);
} else {
$data['sn'] = 1;
}
$this->load->view('user_view',$data);
function get_all()
{
if (is_array($_GET) && (count($_GET) > 0))
{
$this->page = $_GET['per_page'];
foreach($_GET as $index => $value)
{
if($index != 'SortBy' && $index != 'OrderBy' && $index != 'Submit' && $index != 'c' && $index != 'per_page' && $value <> '')
{
$this->db->where($index.' like "%'.$value.'%"');
}
}
}
//check query
//$this->db->debug = true;
$start = ($this->page * $this->limit);
$this->db->orderby('Email','asc');
$query = $this->db->get('users', $this->limit, $start);
return $query->result();
}
function countTotal()
{
if (is_array($_GET) && (count($_GET) > 0))
{
foreach($_GET as $index => $value)
{
if($index != 'SortBy' && $index != 'OrderBy' && $index != 'Submit' && $index != 'c' && $index != 'per_page' && $value <> '')
{
$this->db->where($index.' like "%'.$value.'%"');
}
}
}
$query = $this->db->get('users');
return $query->num_rows();
}
function paging($total = 0)
{
$strURL = '';
if (is_array($_GET) && (count($_GET) > 0))
{
foreach($_GET as $index => $value)
{
if($index <> 'per_page' && $index <> 'c' && $index <> 'm')
{
$strURL .= '&'.$index.'='.$value;
}
}
}
$this->load->library('pagination');
$config['base_url'] = $this->config->config['base_url'].'user/index/?c=user'.$strURL;
$config['total_rows'] = ceil($total/$this->limit);
$config['per_page'] = '1';
$config['num_links'] = 5;
$this->pagination->initialize($config);
return $this->pagination->create_links();
}
[/quote]