| Viewing file:  sa_sourcebudget_model.php (2.38 KB)      -rwxr-xr-x Select action/file-type:
 
  (+) |  (+) |  (+) | Code (+) | Session (+) |  (+) | SDB (+) |  (+) |  (+) |  (+) |  (+) |  (+) | 
 
<?php
 include_once("da_sa_sourcebudget.php");
 
 class Sa_sourcebudget_model extends Da_sa_sourcebudget {
 
 /*
 * 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_sourcebudget
 $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->sb_id] = $row->sb_name;
 }
 return $opt;
 }
 
 // add your functions here
 
 function qu_all(){
 $sql = "select p.sb_id as p_sb_id, p.sb_name as p_sb_name,p.sb_pid as p_sb_pid,c.*
 from
 (
 SELECT * FROM sa_sourcebudget where sb_pid=0
 )p left join
 (
 SELECT * FROM sa_sourcebudget where sb_pid!=0
 )c on p.sb_id = c.sb_pid
 order by p_sb_id, sb_id";
 $query = $this->db->query($sql);
 return $query;
 }
 
 function delete_parent() {
 $sql = "DELETE FROM  $this->sa_dbname.sa_sourcebudget
 WHERE sb_pid=?";
 $query = $this->db->query($sql, array($this->sb_id));
 }
 
 function check_rep_name() {
 ($this->sb_id == '') ? $cond = '' : $cond = "AND sb_id <> $this->sb_id";
 
 $sql = "SELECT * FROM  $this->sa_dbname.sa_sourcebudget
 WHERE sb_name = ? AND sb_pid = ? $cond";
 $query = $this->db->query($sql, array($this->sb_name,$this->sb_pid));
 return $query;
 }
 
 function qu_joinparent() {
 $sql = "
 SELECT c.*, p.sb_name as p_name FROM sa_sourcebudget as c
 LEFT JOIN sa_sourcebudget as p ON p.sb_id = c.sb_pid
 WHERE c.sb_id = ?";
 $query = $this->db->query($sql,array($this->sb_id));
 return $query;
 }
 
 } // end class Sa_sourcebudget_model
 ?>
 |