gundambison

fungsi get CI

Feb 28th, 2018
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.02 KB | None | 0 0
  1. /***
  2. menarik data memanfaatkan filter
  3. * filter (array)
  4. * limit => max data yg tampil
  5. * start => mulai start pada posisi xx
  6. * count => hanya mengembalikan nilai
  7. * debug => mengembalikan versi debug yang dapat di analisa
  8. */
  9.     function item_get_data($filter = array(), $limit = 10, $start = 0, $count = FALSE, $debug = FALSE) {
  10.         $head_table = 'main';
  11.         $this->db_main->reset_query();
  12.         $this->db_main->from($this->tables_realname[$head_table]." i");
  13.         //category
  14.         $this->db_main->join($this->tables_realname['category']." c","i.item_cat=c.cat_code","left");
  15.  
  16.         if (isset($filter['get_all'])) {
  17.             $this->db_main->where($filter['get_all'][0], $filter['get_all'][1]);
  18.         }
  19.  
  20.         if (isset($filter['where_field'])) {
  21.             $this->db_main->where($filter['where_field']);
  22.         }
  23.         if (isset($filter['where_like_field'])) {
  24.             $this->db_main->like($filter['where_like_field']);
  25.         }
  26.  
  27.         if (!isset($filter['show_all'])) {
  28.             $this->db_main->where('i.deleted', 0);
  29.         }
  30.  
  31.         //==============COUNT=============
  32.         if ($count) {
  33.             $this->db_main->select("count({$this->tables_id[$head_table]}) c");
  34.             $data = $this->db_fetch(TRUE);
  35.             return $data['c'];
  36.         }
  37.  
  38.         //==================SHOW==========    
  39.         if (isset($filter['show_fields'])) {
  40.             $this->db_main->select($filter['show_fields']);
  41.         }
  42.         //================order by=== kondisikan
  43.         if (!isset($filter['order_by'])) {
  44.             $this->db_main->order_by('kode', 'asc');
  45.         } else {
  46.             $this->db_main->order_by($filter['order_by'][0], $filter['order_by'][1]);
  47.         }
  48.  
  49.         $this->db_main->limit($limit, $start);
  50.  
  51.         $data = $this->db_fetch();
  52.         if ($debug) {
  53.             $sql = $this->db_main->last_query();
  54.             return array('data' => $data, 'sql' => $sql, 'filter' => $filter);
  55.         } else {
  56.             return $data;
  57.         }
  58.     }
Advertisement
Add Comment
Please, Sign In to add comment