db->select('A.* , users.name as user_name '); $this->db->from('history A'); $this->db->join('users', 'users.id = A.created_by', 'left'); $this->db->where('md5(A.primary_id)', $id); if($business_id != NULL) { $this->db->where('A.business_id', $business_id); } $this->db->where('A.table_name', $table); $this->db->order_by('A.id','DESC'); $query = $this->db->get(); $query = $query->result(); return $query; } }