db_onedev = $this->load->database("onedev", true); } public function searchbyname() { try { //# cek token valid if (! $this->isLogin) { $this->sys_error("Invalid Token"); exit; } $prm = $this->sys_input; $search = $prm['search']; // parameter $number_limit = 10; $number_offset = ($prm['page'] - 1) * $number_limit ; $sql = "SELECT COUNT(*) as total from m_sex where M_SexIsActive = 'Y' AND m_sexname LIKE CONCAT('%','{$search}','%')"; $query = $this->db_onedev->query($sql); $tot_count = 0; $tot_page = 0; if ($query) { $tot_count = $query->result_array()[0]["total"]; $tot_page = ceil($tot_count/$number_limit); } else { $this->sys_error_db("m_sex count", $this->db_onedev); exit; } $sql = "select M_SexID, m_sexname FROM m_sex where M_SexIsActive = 'Y' AND m_sexname LIKE CONCAT('%','{$search}','%') ORDER BY m_sexname ASC limit $number_limit offset $number_offset"; $query = $this->db_onedev->query($sql); //echo $this->db_onedev->last_query(); if ($query) { $rows = $query->result_array(); } else { $this->sys_error_db("m_sex select"); exit; } $result = array ("total" => $tot_page, "total_filter"=>count($rows),"records" => $rows); $this->sys_ok($result); } catch(Exception $exc) { $message = $exc->getMessage(); $this->sys_error($message); } } }