db->select('s.*,r.name as rolename'); $this->db->from('staff as s'); $this->db->join('staff_roles as r','r.id=s.role','inner'); $this->db->where(array('s.status'=>1)); if($id!=0){$this->db->where(array('s.id'=>$id));} $query = $this->db->get(); //echo $this->db->last_query();exit; return $query; } }