Viewing file:      sa_student_model.php (3.46 KB)      -rwxr-xr-x Select action/file-type:    (+) |   (+) |   (+) | Code (+) | Session (+) |   (+) | SDB (+) |   (+) |   (+) |   (+) |   (+) |   (+) |
 
<?php
 
 include_once("da_sa_student.php");
 
 class Sa_student_model extends Da_sa_student {
 
     public $rgAcY;
     /*
      * 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 $this->rg_dbname.rg_Student 
                 $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 *
                     FROM $this->rg_dbname.rg_Student
                     WHERE stdName like '$q%' AND stdSstId = 1";
         $query = $this->db->query($sql);
         $s = "[";
         foreach ($query->result() as $row){
             $s.= "\"$row->stdCode: $row->stdName $row->stdSurname\", ";
         }
         $s = substr($s,0,strlen($s)-2);
         $s.= "]";    
         return $s;
     }
     //19/8/2554
     function getList_json($q=""){
         /*
         $con = '';
         $con.=($this->rgAcY!='')?" AND rgAcY = $this->rgAcY":'';
         $sql = "
             SELECT std . *, rgSyId
             FROM $this->rg_dbname.rg_Regist
             INNER JOIN $this->rg_dbname.rg_Student std ON rgStdId = stdId
             WHERE 1=1 AND stdSstId = 1 
             $con
             GROUP BY rgStdId
                     ";
         */
         $sql = "
             SELECT *
             FROM $this->rg_dbname.rg_Student
             WHERE 1=1 AND stdSstId = 1 
                     ";
         $query = $this->db->query($sql);
         return $query;
     }
 
     function getList2(){
         $sql = "SELECT *
                 FROM $this->rg_dbname.rg_Student
                 WHERE stdName LIKE ?
                 AND stdSurname LIKE ?
                 AND stdCode LIKE ?
                 AND stdSstId = 1
                 ORDER BY
                 CONVERT (stdName USING tis620),
                 CONVERT (stdSurname USING tis620)";
         $query = $this->db->query($sql,array("%".$this->std_name."%", "%".$this->std_surname."%", "%".$this->std_code."%"));
         return $query;
     }
 
     function get_std_id($std_code) {
 
         $sql = "SELECT *
                     FROM $this->rg_dbname.rg_Student
                     WHERE stdCode = ?";
         $query = $this->db->query($sql, array($std_code));
         return $query;
     }
 
     function getListCrs($q=""){
         $sql = "SELECT crsId, crsCode, crsName, curName
                 FROM $this->rg_dbname.rg_Curriculum
                 INNER JOIN $this->rg_dbname.rg_ProgramCourses ON curId = pcrCsCurId
                 INNER JOIN $this->rg_dbname.rg_Course ON crsId = pcrCrsId
                 WHERE curStatus LIKE 'Y'";
         $query = $this->db->query($sql);
         $s = "[";
         foreach ($query->result() as $row){
             $s.= "\"$row->crsId: $row->crsCode $row->crsName [$row->curName]\", ";
         }
         $s = substr($s,0,strlen($s)-2);
         $s.= "]";    
         return $s;
     }
 
 
 } // end class Sa_student_model
 ?>
  |