Viewing file: sa_dm_book_model.php (2.08 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
include_once("da_sa_dm_book.php");
class Sa_dm_book_model extends Da_sa_dm_book {
/*
* aOrderBy = array('fieldname' => 'ASC|DESC', ... )
*/
function get_all($aOrderBy=""){
$orderBy = "";
if ( is_array($aOrderBy) ) {
$orderBy.= "ORDER BY ";
foreach ($aOrderBy as $key => $value) {
$orderBy.= "$key $value, ";
}
$orderBy = substr($orderBy, 0, strlen($orderBy)-2);
}
$sql = "SELECT *
FROM sa_dm_book
$orderBy";
$query = $this->db->query($sql);
return $query;
}
/*
* create array of pk field and value for generate select list in view, must edit PK_FIELD and FIELD_NAME manually
* the first line of select list is '-----เลือก-----' by default.
* if you do not need the first list of select list is '-----เลือก-----', please pass $optional parameter to other values.
* you can delete this function if it not necessary.
*/
function get_options($optional='y') {
$qry = $this->get_all();
if ($optional=='y') $opt[''] = '-----เลือก-----';
foreach ($qry->result() as $row) {
$opt[$row->PK_FIELD] = $row->FIELD_NAME;
}
return $opt;
}
// add your functions here
function get_duplicate() {
$sql = "SELECT *
FROM $this->sa_dbname.sa_dm_book
INNER JOIN $this->ppc_dbname.spc_Place ON dmb_dm_id = plHwId
WHERE dmb_citizen_id = ?
AND dmb_year = ?
AND dmb_tm_id = ?";
$query = $this->db->query($sql, array($this->dmb_citizen_id, $this->dmb_year, $this->dmb_tm_id));
return $query;
}
function get_book() {
$sql = "SELECT dmb.*, pl1.plHwId AS plHwId,
IF(pl1.plBuilding, pl1.plRmNo, pl1.hwName) AS hwName1,
pl2.hwName AS hwName2
FROM $this->sa_dbname.sa_dm_book dmb
INNER JOIN $this->ppc_dbname.spc_Place pl1 ON dmb_dm_id = pl1.plHwId
LEFT JOIN $this->ppc_dbname.spc_Place pl2 ON pl1.plBuilding = pl2.plHwId
WHERE dmb_citizen_id = ?
AND dmb_year = ?
AND dmb_tm_id = ?";
$query = $this->db->query($sql, array($this->dmb_citizen_id, $this->dmb_year, $this->dmb_tm_id));
return $query;
}
} // end class M_sa_dm_book
?>
|