Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * _POST tidak boleh digunakan di model. karena fungsinya agar dapat digunakan
- * dengan parameter non POST kedepannya
- * dari conctroller yang ngirim POST jgn dari model baca POST
- */
- class User_model extends CI_Model {
- var $table = 'service'; //nama tabel dari database
- var $column_order = array(
- null, 'no_rangka', 'no_polisi', 'model', 'type',
- 'transmission', 'warna', 'tahun', 'km', 'customer',
- 'telephone', 'handphone', 'contact_person', 'telephone_cp', 'cabang_penjual',
- 'cabang_service', 'salesman', 'last_service', 'job', 'pekerjaan_utama',
- 'program_promo', 'status_aktif', 'hasil_fu1', 'hasil_fu2', 'hasil_fu3'
- ); //field yang ada di table user
- var $column_search = array(
- 'no_rangka', 'no_polisi', 'model', 'type', 'transmission',
- 'warna', 'tahun', 'km', 'customer', 'telephone',
- 'handphone', 'contact_person', 'telephone_cp', 'cabang_penjual', 'cabang_service',
- 'salesman', 'last_service', 'job', 'pekerjaan_utama', 'program_promo'
- , 'status_aktif', 'hasil_fu1', 'hasil_fu2', 'hasil_fu3'
- ); //field yang diizin untuk pencarian
- var $order = array(
- 'nomor' => 'asc'
- ); // default order
- public function __construct() {
- parent::__construct();
- $this->load->database();
- }
- private function _get_datatables_query($input) {
- $this->db->from($this->table);
- $i = 0;
- if (isset($input['search']['value']) && strlen($input['search']['value']) > 3) {
- // if datatable send POST for search
- $search = explode(" ", $input['search']['value']);
- foreach ($search as $txt) {
- $this->db->group_start(); // open bracket. query Where with OR clause better with bracket. because maybe can combine with other WHERE with AND.
- foreach ($this->column_search as $item) { // loop column
- //if ($i === 0) { // first loop
- // $this->db->like($item, $input['search']['value']);
- //} else
- {
- $this->db->or_like($item, $txt);
- }
- //if(count($this->column_search) - 1 == $i) //last loop
- $i++;
- }
- $this->db->group_end(); //close bracket
- }
- }
- if (isset($input['order'])) { // here order processing
- $this->db->order_by($this->column_order[$input['order']['0']['column']], $input['order']['0']['dir']);
- } else if (isset($this->order)) {
- $order = $this->order;
- $this->db->order_by(key($order), $order[key($order)]);
- }
- }
- function get_datatables($input) {
- $this->_get_datatables_query($input);
- if ($input['length'] != -1)
- $this->db->limit($input['length'], $input['start']);
- $query = $this->db->get();
- $respon = array('data' => $query->result(), 'sql' => $this->db->last_query());
- return $respon;
- }
- function count_filtered($input) {
- $this->_get_datatables_query($input);
- $query = $this->db->get();
- return $query->num_rows();
- }
- public function count_all() {
- $this->db->from($this->table);
- return $this->db->count_all_results();
- }
- }
- /***
- sql
- SELECT * FROM `service` WHERE
- ( `no_rangka` LIKE '%honda%' ESCAPE '!' OR `no_polisi` LIKE '%honda%' ESCAPE '!' OR `model` LIKE '%honda%' ESCAPE '!' OR `type` LIKE '%honda%' ESCAPE '!' OR `transmission` LIKE '%honda%' ESCAPE '!' OR `warna` LIKE '%honda%' ESCAPE '!' OR `tahun` LIKE '%honda%' ESCAPE '!' OR `km` LIKE '%honda%' ESCAPE '!' OR `customer` LIKE '%honda%' ESCAPE '!' OR `telephone` LIKE '%honda%' ESCAPE '!' OR `handphone` LIKE '%honda%' ESCAPE '!' OR `contact_person` LIKE '%honda%' ESCAPE '!' OR `telephone_cp` LIKE '%honda%' ESCAPE '!' OR `cabang_penjual` LIKE '%honda%' ESCAPE '!' OR `cabang_service` LIKE '%honda%' ESCAPE '!' OR `salesman` LIKE '%honda%' ESCAPE '!' OR `last_service` LIKE '%honda%' ESCAPE '!' OR `job` LIKE '%honda%' ESCAPE '!' OR `pekerjaan_utama` LIKE '%honda%' ESCAPE '!' OR `program_promo` LIKE '%honda%' ESCAPE '!' OR `status_aktif` LIKE '%honda%' ESCAPE '!' OR `hasil_fu1` LIKE '%honda%' ESCAPE '!' OR `hasil_fu2` LIKE '%honda%' ESCAPE '!' OR `hasil_fu3` LIKE '%honda%' ESCAPE '!' ) AND
- ( `no_rangka` LIKE '%manual%' ESCAPE '!' OR `no_polisi` LIKE '%manual%' ESCAPE '!' OR `model` LIKE '%manual%' ESCAPE '!' OR `type` LIKE '%manual%' ESCAPE '!' OR `transmission` LIKE '%manual%' ESCAPE '!' OR `warna` LIKE '%manual%' ESCAPE '!' OR `tahun` LIKE '%manual%' ESCAPE '!' OR `km` LIKE '%manual%' ESCAPE '!' OR `customer` LIKE '%manual%' ESCAPE '!' OR `telephone` LIKE '%manual%' ESCAPE '!' OR `handphone` LIKE '%manual%' ESCAPE '!' OR `contact_person` LIKE '%manual%' ESCAPE '!' OR `telephone_cp` LIKE '%manual%' ESCAPE '!' OR `cabang_penjual` LIKE '%manual%' ESCAPE '!' OR `cabang_service` LIKE '%manual%' ESCAPE '!' OR `salesman` LIKE '%manual%' ESCAPE '!' OR `last_service` LIKE '%manual%' ESCAPE '!' OR `job` LIKE '%manual%' ESCAPE '!' OR `pekerjaan_utama` LIKE '%manual%' ESCAPE '!' OR `program_promo` LIKE '%manual%' ESCAPE '!' OR `status_aktif` LIKE '%manual%' ESCAPE '!' OR `hasil_fu1` LIKE '%manual%' ESCAPE '!' OR `hasil_fu2` LIKE '%manual%' ESCAPE '!' OR `hasil_fu3` LIKE '%manual%' ESCAPE '!' )
- ORDER BY `nomor` ASC LIMIT 25
- {"draw":"29","recordsTotal":4,"recordsFiltered":3,"data":[[1,"ABCEGHI","BM-12","Honda Civic","","Manual","Black","2017","","","","","","","","","","2018-05-19","","","","","","",""],[2,"ABCEGHIzzd","BM-12","Honda Civic","","Manual","Black","2017","","","","","","","","","","2018-05-19","","","","","","",""],[3,"ABCEGHIJKL","BM-13","Honda Civic","","Manual","Black","2017","","","","","","","","","","2018-05-19","","","","","","",""]],"sql":"SELECT * FROM `service` WHERE ( `no_rangka` LIKE '%honda%' ESCAPE '!' OR `no_polisi` LIKE '%honda%' ESCAPE '!' OR `model` LIKE '%honda%' ESCAPE '!' OR `type` LIKE '%honda%' ESCAPE '!' OR `transmission` LIKE '%honda%' ESCAPE '!' OR `warna` LIKE '%honda%' ESCAPE '!' OR `tahun` LIKE '%honda%' ESCAPE '!' OR `km` LIKE '%honda%' ESCAPE '!' OR `customer` LIKE '%honda%' ESCAPE '!' OR `telephone` LIKE '%honda%' ESCAPE '!' OR `handphone` LIKE '%honda%' ESCAPE '!' OR `contact_person` LIKE '%honda%' ESCAPE '!' OR `telephone_cp` LIKE '%honda%' ESCAPE '!' OR `cabang_penjual` LIKE '%honda%' ESCAPE '!' OR `cabang_service` LIKE '%honda%' ESCAPE '!' OR `salesman` LIKE '%honda%' ESCAPE '!' OR `last_service` LIKE '%honda%' ESCAPE '!' OR `job` LIKE '%honda%' ESCAPE '!' OR `pekerjaan_utama` LIKE '%honda%' ESCAPE '!' OR `program_promo` LIKE '%honda%' ESCAPE '!' OR `status_aktif` LIKE '%honda%' ESCAPE '!' OR `hasil_fu1` LIKE '%honda%' ESCAPE '!' OR `hasil_fu2` LIKE '%honda%' ESCAPE '!' OR `hasil_fu3` LIKE '%honda%' ESCAPE '!' ) AND ( `no_rangka` LIKE '%manual%' ESCAPE '!' OR `no_polisi` LIKE '%manual%' ESCAPE '!' OR `model` LIKE '%manual%' ESCAPE '!' OR `type` LIKE '%manual%' ESCAPE '!' OR `transmission` LIKE '%manual%' ESCAPE '!' OR `warna` LIKE '%manual%' ESCAPE '!' OR `tahun` LIKE '%manual%' ESCAPE '!' OR `km` LIKE '%manual%' ESCAPE '!' OR `customer` LIKE '%manual%' ESCAPE '!' OR `telephone` LIKE '%manual%' ESCAPE '!' OR `handphone` LIKE '%manual%' ESCAPE '!' OR `contact_person` LIKE '%manual%' ESCAPE '!' OR `telephone_cp` LIKE '%manual%' ESCAPE '!' OR `cabang_penjual` LIKE '%manual%' ESCAPE '!' OR `cabang_service` LIKE '%manual%' ESCAPE '!' OR `salesman` LIKE '%manual%' ESCAPE '!' OR `last_service` LIKE '%manual%' ESCAPE '!' OR `job` LIKE '%manual%' ESCAPE '!' OR `pekerjaan_utama` LIKE '%manual%' ESCAPE '!' OR `program_promo` LIKE '%manual%' ESCAPE '!' OR `status_aktif` LIKE '%manual%' ESCAPE '!' OR `hasil_fu1` LIKE '%manual%' ESCAPE '!' OR `hasil_fu2` LIKE '%manual%' ESCAPE '!' OR `hasil_fu3` LIKE '%manual%' ESCAPE '!' ) ORDER BY `nomor` ASC LIMIT 25"}
- ***/
Advertisement
Add Comment
Please, Sign In to add comment