db_smartone = $this->load->database("onedev", true); } public function search() { $prm = $this->sys_input; $max_rst = 25; $tot_count =0; $q = [ 'search' => '%', 'sex_id' => 0 ]; if ($prm['search'] != '') $q['search'] = "%{$prm['search']}%"; if ($prm['sex_id'] != '') $q['sex_id'] = $prm['sex_id']; // QUERY TOTAL $sql = "select count(*) total from m_title where M_TitleIsActive = 'Y' and M_TitleName like ? and ((M_TitleM_SexID = {$q['sex_id']} and {$q['sex_id']} <> 0) or {$q['sex_id']} = 0)"; $query = $this->db_smartone->query($sql, array($q['search'])); if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("m_sex count",$this->db_smartone); exit; } $sql = "select M_SexID, M_SexName from m_sex where M_SexIsActive = 'Y' and M_SexName like ? limit {$max_rst}"; $query = $this->db_smartone->query($sql, array($q['search'])); if ($query) { $rows = $query->result_array(); $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows)); $this->sys_ok($result); } else { $this->sys_error_db("m_sex rows",$this->db_smartone); exit; } } }