Files
REG_IBL/one-api/application/controllers/mockup/clinic/fo/Sex.php
2026-05-25 20:01:37 +07:00

73 lines
1.9 KiB
PHP

<?php
class Sex extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Sex API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
$max_rst = 25;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "select count(*) total
from
m_sex
where M_SexIsActive = 'Y'
and M_SexName 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_sex count",$this->db_smartone);
exit;
}
$sql = "select M_SexID, M_SexName, concat('[', group_concat(json_object('M_TitleID', M_TitleID, 'M_TitleName', M_TitleName) separator ','), ']') as title
from m_sex
left join m_title on m_titlem_sexid = m_sexid and m_titleisactive = 'Y'
where M_SexIsActive = 'Y'
and M_SexName like ?
group by m_sexid
limit {$max_rst}";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
foreach ($rows as $k => $v)
$rows[$k]['title'] = json_decode($v['title']);
$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;
}
}
}