I am trying to implement a load more feature in a web app I am building. When the app loads, it makes an ajax call to controller which retrieves the data from the database and then encodes them in JSON. I am making use of limits and offsets in mysql query and I more data to be loaded as the user scrolls down. This is the method in the controller which the ajax call is made to
function latest_pheeds($offset = 0) {
//Confirm if a user is logged before allowing access
if($this->isLogged())
{
//Limit
$limit = 20;
//user id
$user_id = $this->session->userdata('user_id');
//load pheeds
$dt = $this->pheed_model->get_latest_pheeds($limit,$offset);
$data = $dt['pheeds']; //data
$total = $dt['total']; //Total no of rows of data
$return['pheeds'] = $data;
echo json_encode($return); //encode in json
} else {
$this->output->set_status_header('401',"Attempting Unauthorized Access");
}
}
How do I break this data into pages, so I can simply pass the page no as argument to method via the ajax call to implement the load more with jQuery?