96 lines
2.0 KiB
PHP
96 lines
2.0 KiB
PHP
<?php
|
|
|
|
/**
|
|
*
|
|
*/
|
|
class Province extends MY_Controller
|
|
{
|
|
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
function search()
|
|
{
|
|
|
|
// $this->sys_debug();
|
|
try
|
|
{
|
|
// Token validation
|
|
if (! $this->isLogin)
|
|
{
|
|
$this->sys_error("Invalid Token");
|
|
exit;
|
|
}
|
|
|
|
// Getting inputs
|
|
$prm = $this->sys_input;
|
|
$s_query = "%" . $prm["query"] . "%";
|
|
|
|
// Predefined values
|
|
$row_per_page = 25;
|
|
$page = 1;
|
|
$tot_count = 0;
|
|
|
|
$sqlc = "SELECT COUNT(*) as n
|
|
FROM m_province
|
|
WHERE M_ProvinceName LIKE ? AND M_ProvinceIsActive='Y'";
|
|
|
|
if (isset($prm["row_per_page"])) $row_per_page = $prm["row_per_page"];
|
|
if (isset($prm["page"])) $page = $prm["page"];
|
|
|
|
$sql_param = array($s_query);
|
|
|
|
// Getting total rows
|
|
$sql = $sqlc;
|
|
$query = $this->db->query($sql, $sql_param);
|
|
if ($query) {
|
|
$tot_count = $query->row()->n;
|
|
} else {
|
|
$this->sys_error_db("m_sex count");
|
|
exit;
|
|
}
|
|
|
|
// Getting records if count > 0
|
|
$rows = array();
|
|
if ($tot_count > 0)
|
|
{
|
|
// Start_limit < 0 ? > total_count ?
|
|
$start_limit = ($page - 1) * $row_per_page;
|
|
if ($start_limit > $tot_count)
|
|
$start_limit = 0;
|
|
|
|
if ($start_limit < 0)
|
|
$start_limit = 0;
|
|
|
|
$sql = "SELECT *
|
|
FROM m_province
|
|
WHERE M_ProvinceName like ? and M_ProvinceIsActive='Y'
|
|
LIMIT $start_limit, $row_per_page";
|
|
$query = $this->db->query($sql, $sql_param);
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
} else {
|
|
$this->sys_error_db("m_sex rows");
|
|
exit;
|
|
}
|
|
}
|
|
|
|
$result = array ("total" => $tot_count, "records" => $rows);
|
|
$this->sys_ok($result);
|
|
|
|
}
|
|
|
|
catch(Exception $exc)
|
|
{
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
?>
|