Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.94 KB | None | 0 0
  1. private function _get_datatables_query()
  2.     {
  3.         $id = $this->session->userdata('id');
  4.         if ($id != 0 ){
  5.             $where = "user_id = $id";
  6.             $this->db->from($this->table_data_user);
  7.             $this->db->where($where);
  8.         }
  9.         else{
  10.             $this->db->from($this->table_data_user);
  11.         }
  12.  
  13.         $i = 0;
  14.      
  15.         foreach ($this->column_search as $item) // looping awal
  16.         {
  17.             if($_POST['search']['value']) // jika datatable mengirimkan pencarian dengan metode POST
  18.             {
  19.                  
  20.                 if($i===0) // looping awal
  21.                 {
  22.                     $this->db->group_start();
  23.                     $this->db->like($item, $_POST['search']['value']);
  24.                 }
  25.                 else
  26.                 {
  27.                     $this->db->or_like($item, $_POST['search']['value']);
  28.                 }
  29.  
  30.                 if(count($this->column_search) - 1 == $i)
  31.                     $this->db->group_end();
  32.             }
  33.             $i++;
  34.         }
  35.          
  36.         if(isset($_POST['order']))
  37.         {
  38.             $this->db->order_by($this->column_order[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
  39.         }
  40.         else if(isset($this->order))
  41.         {
  42.             $order = $this->order;
  43.             $this->db->order_by(key($order), $order[key($order)]);
  44.         }
  45.     }
  46.  
  47.     function get_datatables()
  48.     {
  49.         $this->_get_datatables_query();
  50.         if($_POST['length'] != -1)
  51.         $this->db->limit($_POST['length'], $_POST['start']);
  52.         $query = $this->db->get();
  53.         return $query->result();
  54.     }
  55.  
  56.     function count_filtered()
  57.     {
  58.         $this->_get_datatables_query();
  59.         $query = $this->db->get();
  60.         return $query->num_rows();
  61.     }
  62.  
  63.     public function count_all()
  64.     {
  65.         $this->_get_datatables_query();
  66.         return $this->db->count_all_results();
  67.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement