CodeIgniter Forums

Full Version: Problem in Pagination
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]zombica[/eluser]
Hey guys i am doing pagination and i am unable to resolve this thing. I am getting the value of $this->uri->segment(4) for my offset but it returns nothing.

class Users extends Controller {

function Users(){

parent::Controller();
$this->load->model('usermodel');
$this->load->library('pagination');
$this->load->library('session');
$this->load->helper('url');
$this->load->helper('form');
$this->load->helper('date');
$this->load->library('validation');
$this->load->library('email');

}

function users_view(){

/// set page title
$this->data['title'] = 'View Users Records ';
$this->load->vars($this->data);

/******Paginating Records********/
$rows=$this->db->count_all("tms_user");
$base=base_url();
$config['base_url'] =base_url().$this->config->item('index_page').'/'.'users/users_view';
$config['total_rows'] = $rows;
$config['per_page'] = '5';
$config['uri_segment'] = 4;
$config['num_links'] = 4;
$config['first_link'] = '«';
$config['last_link'] = '»';
$config['next_link'] = '>';
$config['prev_link'] = '<';
$this->pagination->initialize($config);

/*******************************/
$data=$this->load_leftmenu();
$user_id = $_SESSION['user_id'];
$data['alluserList'] = $this->usermodel->get_all_user($config['per_page'],$this->uri->segment(4),$user_id); //
$this->load->view('users_view',$data);
exit;
}


A Database Error Occurred

SELECT * from tms_user where userId <> 1 and deleted='0' order by username LIMIT 5,


Regards,
Thanx in advance.....

El Forum

[eluser]Thorpe Obazee[/eluser]
[quote author="zombica" date="1246014496"]
Code:
$config['base_url'] =base_url().$this->config->item('index_page').'/'.'users/users_view'
;[/quote]

it could be easier to just use. site_url('users/users_view');

Anyway, try $this->uri->segment(3) here

Code:
$data[‘alluserList’] = $this->usermodel->get_all_user($config[‘per_page’],$this->uri->segment(4),$user_id);

El Forum

[eluser]zombica[/eluser]
Thanx... Buddy you there again for resolving my problem. Hey man this doesn't affect any thing same DB error showing nothing for offset.

El Forum

[eluser]Thorpe Obazee[/eluser]
Code:
$config[‘uri_segment’] = 4;

Is there any reason why you're using segment 4? It seems that the segment should be 3. Are you using routing?

Can you show get_all_user() from the model?

El Forum

[eluser]zombica[/eluser]
Here it goes....

//Get All users data
function get_all_user($num,$offset,$user_id)
{
$query = $this->db->query("SELECT * from tms_user where userId <> $user_id and deleted='0' order by username LIMIT ".$num.",".$offset." ");
$result=$query->result();
return $result;
}

El Forum

[eluser]zombica[/eluser]
No i can use $this->uri->segment(3) .. i am not using any kind of routing. I have done this by both 3 and 4. It doesn't affects.

El Forum

[eluser]Thorpe Obazee[/eluser]
Try using the AR. I assume the problem occurs on the first page only. Nothing is preventing the ',' comma from getting in your query which causes the error.

Code:
$this->db->where(array('userId' <> =>$user_id, 'deleted' => 0));
$this->db->order_by('username');
$this->db->limit($num, $offset);
$query = $this->db->get('tms_user');

if ($query->num_rows() > 0)
{
    return $query->result();
}
return FALSE;

El Forum

[eluser]zombica[/eluser]
Yes problem is with only the first page it does not comes once we are in some inner page.

Giving parse error on this line....
$this->db->where(array('userId' <> =>$user_id, 'deleted' => 0));

El Forum

[eluser]zombica[/eluser]
Thanx it resolve. Thanx buddy a lot.