db_smartone = $this->load->database("onedev", true); } public function search() { $prm = $this->sys_input; $max_rst = 12; $tot_count =0; $q = [ 'search' => '%' ]; if ($prm['search'] != '') { $q['search'] = "%{$prm['search']}%"; } // QUERY TOTAL $sql = "select count(*) total from m_doctor JOIN m_doctorpj ON M_DoctorID = M_DoctorPJM_DoctorID and M_DoctorIsActive = 'Y' where M_DoctorIsActive = 'Y' and M_DoctorPJIsClinic = 'Y' and M_DoctorName like ?"; $query = $this->db_smartone->query($sql, array($q['search'])); if ($query) { $tot_count = $query->result_array()[0]["total"]; } else { $this->sys_error_db("m_patient count",$this->db_smartone); exit; } $sql = "select M_DoctorID, M_DoctorIsDefault, M_DoctorIsPJ, concat(IFNULL(M_DoctorPrefix, ''),' ',M_DoctorName, ' ', IFNULL(M_DoctorSufix, '')) as M_DoctorName, IFNULL( concat('[', group_concat(JSON_OBJECT('M_DoctorAddressDescription', M_DoctorAddressDescription, 'M_DoctorAddressID', M_DoctorAddressID) SEPARATOR ','), ']'), '[]') as address from m_doctor JOIN m_doctorpj ON M_DoctorID = M_DoctorPJM_DoctorID and M_DoctorIsActive = 'Y' left join m_doctoraddress on M_DoctorAddressIsActive = 'Y' and M_DoctorAddressM_DoctorID = M_DoctorID where M_DoctorPJIsActive = 'Y' and M_DoctorIsClinic = 'Y' and concat(IFNULL(M_DoctorPrefix, ''),' ',M_DoctorName, ' ', IFNULL(M_DoctorSufix, '')) like ? group by M_DoctorID"; $query = $this->db_smartone->query($sql, array($q['search'])); if ($query) { $rows = $query->result_array(); foreach ($rows as $k => $v) $rows[$k]['address'] = json_decode($v['address']); $result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows)); $this->sys_ok($result); } else { $this->sys_error_db("m_doctor rows",$this->db_smartone); exit; } } }