File: //var/www/html/taxicamera/pmw_live_testing/application/models/Muser.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Muser extends CI_Model {
var $table = 'users';
var $order = array('id' => 'desc'); // default order
public function __construct() {
echo '1';exit();
parent::__construct();
}
private function _get_datatables_query(){
$this->db->from($this->table);
$i = 0;
foreach ($this->column_search as $item){ // loop column
if($_POST['search']['value']){ // if datatable send POST for search
if($i===0){ // first loop
$this->db->group_start(); // open bracket. query Where with OR clause better with bracket. because maybe can combine with other WHERE with AND.
$this->db->like($item, $_POST['search']['value']);
}
else{
$this->db->or_like($item, $_POST['search']['value']);
}
if(count($this->column_search) - 1 == $i) //last loop
$this->db->group_end(); //close bracket
}
$i++;
}
if(isset($_POST['order'])){ // here order processing
$this->db->order_by($this->column_order[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
}else if(isset($this->order)){
$order = $this->order;
$this->db->order_by(key($order), $order[key($order)]);
}
}
public function get_datatables(){
$this->_get_datatables_query();
if($_POST['length'] != -1)
$this->db->limit($_POST['length'], $_POST['start']);
$query = $this->db->get();
return $query->result();
}
public function count_filtered(){
$this->_get_datatables_query();
$query = $this->db->get();
return $query->num_rows();
}
public function count_all(){
$this->db->from($this->table);
return $this->db->count_all_results();
}
public function get_details($user_id){
$this->db->select('*');
$this->db->from($this->table);
$this->db->where('user_id',$user_id);
$query=$this->db->get();
return $query->row_array();
}
public function update($condition,$data){
$this->db->where($condition);
$this->db->update($this->table,$data);
return 1;
}
public function add($data){
$this->db->insert($this->table,$data);
return true;
}
public function delete($condition){
$this->db->delete($this->table,$condition);
return 1;
}
public function getRow($org_password,$user_name){
$this->db->select('*');
//$this->db->where('password',$password);
$this->db->where('email', $user_name);
$this->db->or_where('mobile_no', $user_name);
$this->db->or_where('card_number', $user_name);
$query=$this->db->get('users');
//echo $this->db->last_query();die;
return $query->row_array();
}
public function get_all(){
$this->db->select('*');
$this->db->from($this->table);
$query=$this->db->get();
return $query->result_array();
}
}