offset is not working

offset is not working

RookieProgrammerRookieProgrammer Posts: 4Questions: 3Answers: 0

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,


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');
         return $query->result();


public function ajax() {
    $user_data= $this->UserDashboard->userData();
    $data = array();
    foreach($user_data as $row){
        $data[] =array(
            "<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>"
        'recordsTotal' => $totalRows,
        'recordsFiltered' => $totalRows,
    echo json_encode($output);  



defined('BASEPATH') OR exit('No direct script access allowed');
<!DOCTYPE html>
<html lang="">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src=""></script>
    <script src=""></script>
    <link rel="stylesheet" type="text/css" href=""/>
    <link href="" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
<!-- style="background:url(<?php echo base_url();?>/assets/css/Wireframe.png);" -->
<div class="container-fluid text-center">
    <h1>User Dashboard</h1>
    Welcome, <?php get_cookie('username')?>
    <a href="<?php echo site_url('home/logout');?>" class="btn btn-primary">Logout</a>
<div class="container-fluid ">
    <table id="tableData" class="table table-hover text-black">
                <th>User Id</th>
                <th>User Name</th>
                <th>First Name</th>
                <th>Last Name</th>
                <th>Profile Pic</th>
<!-- <script src="<?php echo base_url();?>/assets/js/bootstrap.min.js"></script>  -->

$(document).ready(function() {
        //"processing": true,
        'serverSide': true,
            'url':"<?php base_url();?>ajax",
            // "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"}
            //  ],


This discussion has been closed.