title: Datatables error Undefined index Codeigniter
body: <p>I have been using datatables before but this is the first time I encountered this type of error.</p>
  
  <p>I have errors:</p>
  
  <pre><code>Message: Undefined index: order
  Message: Undefined index: start
  Message: Undefined index: length
  
  Message: Call to a member function result_array() on boolean
  
  Line: 253
  </code></pre>
  
  <p>(I just shortcut the errors)</p>
  
  <p>My ajax code:</p>
  
  <pre><code>var dataTable = $('#table-grid').DataTable({ // *** This is for Data Table
      "processing": true,
      "serverSide": true,
      columnDefs: [
          { orderable: false, targets: [6,5]},
          { class: "text-center", targets: [5,6]},
      ],
      "ajax":{
          url :base_url+"LandClient/view_properties", // json datasource
          type: "post",  // method  , by default get
          data: {'email': $('#email').val()},
          error: function(){  // error handling
              $(".table-grid-error").html("");
              $("#table-grid").append('&lt;tbody class="table-grid-error"&gt;&lt;tr&gt;&lt;th colspan="5"&gt;No data found in the server&lt;/th&gt;&lt;/tr&gt;&lt;/tbody&gt;');
              $("#table-grid_processing").css("display","none");
          }
      }
  });
  </code></pre>
  
  <p>My controller:</p>
  
  <pre><code>public function view_properties(){
      $email = $this-&gt;session-&gt;userdata('login_email');
      generate_json($this-&gt;LandClientModel-&gt;view_properties($email));
  }
  </code></pre>
  
  <p>My model:</p>
  
  <pre><code>public function view_properties($email){
      // storing  request (ie, get/post) global array to a variable  
      $requestData= $_REQUEST;
  
  
      $columns = array( 
          // datatable column index  =&gt; database column name for sorting
              0 =&gt; 'pr.date_created',
              1 =&gt; 'dc.tdn_no',
              2 =&gt; 'oct.orig_cert_no,tct.orig_cert_no',
              3 =&gt; 'tct_no',
              4 =&gt; 'owner_name',
              5 =&gt; 'pr.status',
          );
  
      // getting total number records without any search
  
      $sql = "SELECT *,oct.orig_cert_no as oct1, tct.orig_cert_no as oct2  FROM land_property pr 
              LEFT JOIN land_property_orig_title oct ON pr.prop_id = oct.prop_id
              LEFT JOIN land_property_transfer_title tct ON pr.prop_id = tct.prop_id
              LEFT JOIN land_property_declaration dc ON pr.prop_id = dc.prop_id
              WHERE pr.email = ? ";
      $params = array($email);
      $query = $this-&gt;db-&gt;query($sql, $params);
      $totalData = $query-&gt;num_rows();
  
      $totalFiltered = $totalData;  // when there is no search parameter then total number rows = total number filtered rows.
  
  
  
  
  
      if( !empty($requestData['columns'][0]['search']['value']) ) //email address
      { 
          $sql.=" AND tdn_no LIKE '%". $this-&gt;db-&gt;escape_like_str(sanitize($requestData['columns'][0]['search']['value']))."%' ";
      }
  
      if( !empty($requestData['columns'][1]['search']['value']) ) //email address
      { 
          $sql.=" AND oct.orig_cert_no LIKE '%". $this-&gt;db-&gt;escape_like_str(sanitize($requestData['columns'][1]['search']['value']))."%' OR tct.orig_cert_no LIKE '%". $this-&gt;db-&gt;escape_like_str(sanitize($requestData['columns'][1]['search']['value']))."%' ";
      }
  
  
      if( !empty($requestData['columns'][2]['search']['value']) ) //email address
      { 
          $sql.=" AND owner_name LIKE '%". $this-&gt;db-&gt;escape_like_str(sanitize($requestData['columns'][2]['search']['value']))."%' ";
      }
  
  
      if( !empty($requestData['columns'][3]['search']['value']) ) //email address
      { 
          $sql.=" AND tct_no LIKE '%". $this-&gt;db-&gt;escape_like_str(sanitize($requestData['columns'][3]['search']['value']))."%' ";
      }
  
  
  
      $query = $this-&gt;db-&gt;query($sql, $params);
      $totalFiltered = $query-&gt;num_rows(); // when there is a search parameter then we have to modify total number filtered rows as per search result.
  
       $sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]."   ".$requestData['order'][0]['dir']."   LIMIT ".$requestData['start']." ,".$requestData['length']."   ";  // adding length
  
  
      $query = $this-&gt;db-&gt;query($sql, $params);
      $data = array();
  
      foreach( $query-&gt;result_array() as $row ) {  // preparing an array for table tbody
          $nestedData=array(); 
          // $nestedData[] = $row["date_created"];
              if($row['tdn_no']==''){
                  $tdn = "&lt;h1&gt;-&lt;/h1&gt;";
              } else {
                  $tdn = $row['tdn_no'];
              }
              $nestedData[] = $tdn;
              if($row['oct1']!=""){
                  $nestedData[] = $row["oct1"];
              } else {
                  $nestedData[] = $row["oct2"];
              }
              $nestedData[] = $row["tct_no"]==""?"-":$row["tct_no"];
              $nestedData[] = $row["owner_name"];
  
  
              if($row["status"] == 4){
                  $status = "&lt;span class='badge badge-danger tbl-badge'&gt;Hold&lt;/span&gt;";
              }
              elseif($row["status"] == 1){
                      $status = "&lt;span class='badge badge-success tbl-badge'&gt;Assessed&lt;/span&gt;";
              }
               elseif($row["status"] == 2){
                      $status = "&lt;span class='badge badge-warning tbl-badge'&gt;For Assessment&lt;/span&gt;";
              }
              $nestedData[] = $status;
  
              $nestedData[] = $row["status"];
  
  
  
  
              $nestedData[] = '&lt;button class="btn btn-primary btnView btnView-1 btn-cus" &gt; View&lt;/button&gt;  ';
              $data[] = $nestedData;
      }
      $json_data = array(
          "recordsTotal"    =&gt; intval( $totalData ),  // total number of records
          "recordsFiltered" =&gt; intval( $totalFiltered ), // total number of records after searching, if there is no searching then totalFiltered = totalData
          "data"            =&gt; $data,   // total data array
      );
  
      return $json_data;
  }
  </code></pre>
  
  <p>btw, line 253 is</p>
  
  <pre><code> $sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]."   ".$requestData['order'][0]['dir']."   LIMIT ".$requestData['start']." ,".$requestData['length']."   ";  // adding length
  </code></pre>