Viewing file: sa_person_model.php (2.81 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
include_once("da_sa_person.php");
class Sa_person_model extends Da_sa_person {
/*
* 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_person
$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 getList($q=""){
$sql = "SELECT prsId, personCode, fName, lName FROM $this->ppc_dbname.Person
WHERE fName like '$q%' ORDER BY fName";
$query = $this->db->query($sql) ;
return $this->db->last_query();
$s = "[";
foreach ($query->result() as $row){
$s.= "\"$row->personCode: $row->fName $row->lName \", ";
}
$s = substr($s,0,strlen($s)-2);
$s.= "]";
return $s;
}
function getListTe($q=""){
$sql = "SELECT personId, fName, lName FROM $this->ppc_dbname.Person
WHERE fName like '$q%' ORDER BY fName";
$query = $this->db->query($sql) ;
//return $this->db->last_query();
$s = "[";
foreach ($query->result() as $row){
$s.= "\"$row->personId: $row->fName $row->lName \", ";
}
$s = substr($s,0,strlen($s)-2);
$s.= "]";
return $s;
}
function selectPersonByAdsJoinPPC($sc_id){
$sql = "select * from $this->sa_dbname.sa_adviser_sc ads inner join $this->ppc_dbname.Person prs on ads.ads_prs_id=prs.personId and ads_sc_id='$sc_id';";
$query = $this->db->query($sql) ;
return $query;
}
function getList2($f='',$l=''){
$c = ($f=='')?'':"and prs_name like '$f%'";
$c.= ($l=='')?'':"and prs_surname like '$l%'" ;
$sql = "SELECT prs_id, prs_code, prs_name, prs_surname,prs_type
FROM sa_person
WHERE 1=1
$c
ORDER BY prs_name";
$query = $this->db->query($sql) ;
return $query;
}
} //=== end class M_sa_Person
?>
|