offset is not working
offset is not working
RookieProgrammer
Posts: 4Questions: 3Answers: 0
in General
Dear Fellow Programmers,
I am trying to display records in Pagination using data table in CodeIgniter where my code is counting correctly total number of rows, model is also fetching all records from db even ajax response is showing correctly and limit of 10 records per page works fine as well however I am facing an issue of offset. My records are not changing with change of page.
Kindly suggest me suitable solution for the same
Best Regards,
Jay
Model
class UserDashboard extends CI_Model
{
public function getRows(){
$query2=$this->db->query('SELECT * FROM user_list');
return $query2->num_rows();
}
public function userData(){
$query = $this->db->get('user_list');
$this->db->limit(10,10);
return $query->result();
}
}
Controller
public function ajax() {
$user_data= $this->UserDashboard->userData();
$totalRows=$this->UserDashboard->getRows();
$data = array();
foreach($user_data as $row){
$data[] =array(
$row->user_id,
$row->user_name,
$row->fname,
$row->lname,
$row->eml,
$row->gnd,
$row->ctry,
$row->st,
$row->cty,
"<img height='70' width='70' src='../uploads/".$row->img."'>",
"<a href='edit.php?user_id=". $row->user_id ."' id='edit' class='btn btn-primary'>Edit </a>".
"<a href='remove.php?user_id=". $row->user_id ."' id='delete' class='btn btn-danger'>Delete</a>"
);
}
$output=array(
'draw'=>$_POST['draw'],
'recordsTotal' => $totalRows,
'recordsFiltered' => $totalRows,
'data'=>$data,
);
echo json_encode($output);
}
View
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
<?php
>
<!DOCTYPE html>
Login
User Dashboard
Welcome, <?php get_cookie('username')?>
" class="btn btn-primary">Logout
User Id
User Name
First Name
Last Name
Email
Gender
Country
State
City
Profile Pic
Action
?>
<script>
$(document).ready(function() {
$('#tableData').DataTable({
//"processing": true,
'serverSide': true,
//"searching":true,
//"order":[],
'ajax':{
'url':"<?php base_url();?>ajax",
'type':"POST",
// "columns": [
// {"name": "user_id"},
// {"name": "user_name"},
// {"name": "fname"},
// {"name": "lname"},
// {"name": "eml"},
// {"name": "gnd"},
// {"name": "ctry"},
// {"name": "st"},
// {"name": "cty"},
// {"name": "img"},
// {"name":"Action"}
// ],
}
});
});
</script>
</body>
</html>
This discussion has been closed.