Guest User

Untitled

a guest
Mar 17th, 2016
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.22 KB | None | 0 0
  1.     var $table = 'applications';
  2.     var $column = array( 'Firstname','Lastname','Birthdate','PESEL','Phone' ); //set column field database for order and search
  3.     var $order = array('ID' => 'desc'); // default order
  4.  
  5.     public function __construct()
  6.     {
  7.         parent::__construct();
  8.         $this->load->database();
  9.     }
  10.  
  11.     private function _GetDataTablesQuery()
  12.     {
  13.        
  14.         $this->db->from($this->table);
  15.  
  16.         $i = 0;
  17.    
  18.         foreach ($this->column as $item) // loop column
  19.         {
  20.             if($_POST['search']['value']) // if datatable send POST for search
  21.             {
  22.                
  23.                 if($i===0) // first loop
  24.                 {
  25.                     $this->db->group_start(); // open bracket. query Where with OR clause better with bracket. because maybe can combine with other WHERE with AND.
  26.                     $this->db->like($item, $_POST['search']['value']);
  27.                 }
  28.                 else
  29.                 {
  30.                     $this->db->or_like($item, $_POST['search']['value']);
  31.                 }
  32.  
  33.                 if(count($this->column) - 1 == $i) //last loop
  34.                     $this->db->group_end(); //close bracket
  35.             }
  36.             $column[$i] = $item; // set column array variable to order processing
  37.             $i++;
  38.         }
  39.        
  40.         if(isset($_POST['order'])) // here order processing
  41.         {
  42.             $this->db->order_by($column[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
  43.         }
  44.         else if(isset($this->order))
  45.         {
  46.             $order = $this->order;
  47.             $this->db->order_by(key($order), $order[key($order)]);
  48.         }
  49.     }
  50.  
  51.     function GetApplications()
  52.     {
  53.         $this->_GetDataTablesQuery();
  54.         if($_POST['length'] != -1)
  55.         $this->db->limit($_POST['length'], $_POST['start']);
  56.         $query = $this->db->get();
  57.         return $query->result();
  58.     }
  59.  
  60.     function CountFiltered()
  61.     {
  62.         $this->_GetDataTablesQuery();
  63.         $query = $this->db->get();
  64.         return $query->num_rows();
  65.     }
  66.  
  67.     public function CountAll()
  68.     {
  69.         $this->db->from($this->table);
  70.         return $this->db->count_all_results();
  71.     }
Add Comment
Please, Sign In to add comment