db = $this->load->database("one_doctor", true); } function index() { // $cek = $this->db->query("select database() as current_db")->result(); // print_r($cek); echo "API DOCTOR TEST"; } function lookup() { try { if (!$this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $search = ""; if(isset($prm["search"])) { $search = trim($prm["search"]); if ($search != "") { $search = "%" . $prm["search"] . "%"; }else{ $search = "%%"; } } $number_offset = 0; $number_limit = 10; if ($prm["current_page"] > 0) { $number_offset = ($prm["current_page"] - 1) * $number_limit; } $sql_filter = "SELECT COUNT(DISTINCT M_UserID) as total FROM one_doctor.m_user a JOIN m_doctor b ON a.M_UserM_DoctorID = b.M_DoctorID AND M_UserIsActive = 'Y' AND M_DoctorIsActive = 'Y' JOIN m_mou c ON a.M_UserM_MouID = c.M_MouID AND M_MouIsActive = 'Y' JOIN m_company d ON c.M_MouM_CompanyID = d.M_CompanyID AND M_CompanyIsActive = 'Y' WHERE fn_get_doctor_fullname(M_UserM_DoctorID) like ? OR M_MouNumber like ? OR M_CompanyName like ?"; $qry_filter = $this->db->query($sql_filter, [$search, $search, $search]); // $last_query = $this->db->last_query(); // echo ($last_query); $tot_count = 0; $tot_page = 0; if ($qry_filter) { $tot_count = $qry_filter->result_array()[0]["total"]; $tot_page = ceil($tot_count/$number_limit); } else { $this->sys_error_db("doctor count error", $this->db); exit; } $sql = "SELECT M_UserID as userid, fn_get_doctor_fullname(M_UserM_DoctorID) as doctorName, M_UserM_MouID as mouid, M_UserUsername as username, M_MouNumber as mounumber, M_CompanyID as companyid, M_CompanyName as companyname FROM one_doctor.m_user a JOIN m_doctor b ON a.M_UserM_DoctorID = b.M_DoctorID AND M_UserIsActive = 'Y' AND M_DoctorIsActive = 'Y' JOIN m_mou c ON a.M_UserM_MouID = c.M_MouID AND M_MouIsActive = 'Y' JOIN m_company d ON c.M_MouM_CompanyID = d.M_CompanyID AND M_CompanyIsActive = 'Y' WHERE fn_get_doctor_fullname(M_UserM_DoctorID) like ? OR M_MouNumber like ? OR M_CompanyName like ?"; $qry = $this->db->query($sql, array($search, $search, $search, $number_limit, $number_limit)); // $last_query = $this->db->last_query(); // echo ($last_query); if ($qry) { $rows = $qry->result_array(); } else { $this->sys_error_db("doctor select error", $this->db); exit; } $result = array( "total_page" => $tot_page, "total_filter" => count($rows), "records" => $rows ); $this->sys_ok($result); } catch (Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } } ?>