execQuery($query);
$rsBudget = $dbObj->fetchArray($result);
/** Query เพื่อหา Numrows ก่อน */
if( $keyword != "" ) {
$query = "SELECT * FROM formaoffice LEFT JOIN training_tb ON formaoffice.Training_code = training_tb.Training_code WHERE formaoffice.Teacher_code ='$Teacher_code' AND formaoffice.Year_std = '".$rsBudget["Budget_year"]."' AND (formaoffice.maNo LIKE '%$keyword%' OR formaoffice.Training_name LIKE '%$keyword%') GROUP BY formaoffice.maNo";
}
else {
$query = "SELECT * FROM formaoffice LEFT JOIN training_tb ON formaoffice.Training_code = training_tb.Training_code WHERE formaoffice.Teacher_code = '$Teacher_code' AND formaoffice.Year_std = '".$rsBudget["Budget_year"]."' AND formaoffice.Year_std = '".$rsBudget["Budget_year"]."' GROUP BY formaoffice.maNo";
}
$result = $dbObj->execQuery($query);
$numrows = $dbObj->_numrows;
/** Paging */
$display = ( !isset ($_GET['page']) ) ? 1 : $_GET['page'];
$start = ( ($display * $limit) - $limit );
/** Paging */
//### Search
if( $keyword != "" ) {
if( isset($_GET['OrderBy']) ) {
$query = "SELECT * FROM formaoffice LEFT JOIN training_tb ON formaoffice.Training_code = training_tb.Training_code WHERE formaoffice.Teacher_code = '$Teacher_code' AND formaoffice.Year_std = '".$rsBudget["Budget_year"]."' AND (formaoffice.maNo LIKE '%$keyword%' OR formaoffice.Training_name LIKE '%$keyword%') GROUP BY formaoffice.maNo ORDER BY $OrderBy $ASCDESC ";
}
elseif( !isset($_GET['OrderBy']) ) {
$query = "SELECT * FROM formaoffice LEFT JOIN training_tb ON formaoffice.Training_code = training_tb.Training_code WHERE formaoffice.Teacher_code = '$Teacher_code' AND formaoffice.Year_std = '".$rsBudget["Budget_year"]."' AND (formaoffice.maNo LIKE '%$keyword%' OR formaoffice.Training_name LIKE '%$keyword%') GROUP BY formaoffice.maNo ORDER BY $OrderBy $ASCDESC";
}
}
else {
if(isset($_GET['OrderBy'])){
$query = "SELECT * FROM formaoffice LEFT JOIN training_tb ON formaoffice.Training_code = training_tb.Training_code WHEREformaoffice.Teacher_code = '$Teacher_code' AND formaoffice.Year_std = '".$rsBudget["Budget_year"]."' AND formaoffice.Year_std = '".$rsBudget["Budget_year"]."' GROUP BY formaoffice.maNo ORDER BY $OrderBy $ASCDESC";
}
elseif(!isset($_GET['OrderBy'])) {
$query = "SELECT * FROM formaoffice LEFT JOIN training_tb ON formaoffice.Training_code = training_tb.Training_code WHERE formaoffice.Teacher_code = '$Teacher_code' AND formaoffice.Year_std = '".$rsBudget["Budget_year"]."' AND formaoffice.Year_std = '".$rsBudget["Budget_year"]."' GROUP BY formaoffice.maNo ORDER BY $OrderBy $ASCDESC";
}
}
$query .= " LIMIT $start, $limit ";
$result = $dbObj->execQuery($query);
?>