:::

10-2 上課範例:add_class.php

<?php
//引入共同檔
require_once "header.php";

//變數初始化
$op=isset($_REQUEST['op'])?$_REQUEST['op']:"";
$class_sn=isset($_REQUEST['class_sn'])?intval($_REQUEST['class_sn']):"";

//流程控制
$main=class_form($class_sn);

//套用樣板
theme("theme.html");

/*************** 功能函數區 **************/

//建立班級的表單
function class_form($class_sn=""){
  $next_op="insert";

  //初始值設定
  $data['seme'] = $data['class_name'] = $data['teacher'] = $data['passwd'] = $opt1 = $opt2 = $opt3 = $opt4 = $opt5 = $opt6 = $opt7 = $opt8 = $radio1 = $radio0 = "";
 
  if($class_sn){
   //設定SQL語法
    $sql="select * from `tncomu_class` where class_sn='{$class_sn}'";

    //執行SQL語法
    $result=mysql_query($sql) or die("無法執行:".mysql_error());

    //擷取資料回來存到 $data
    $data=mysql_fetch_assoc($result);

    //還原下拉選單預設值
    $opt1=($data['subject']=="語言與文化")?"selected":"";
    $opt2=($data['subject']=="生命與健康")?"selected":"";
    $opt3=($data['subject']=="社會與生活")?"selected":"";
    $opt4=($data['subject']=="自然與環境")?"selected":"";
    $opt5=($data['subject']=="美學與藝術")?"selected":"";
    $opt6=($data['subject']=="資訊與傳播")?"selected":"";
    $opt7=($data['subject']=="台江分校")?"selected":"";
    $opt8=($data['subject']=="台江大廟興學")?"selected":"";

    $radio1=($data['access']=="1")?"checked":"";
    $radio0=($data['access']=="0")?"checked":"";
    $next_op="update";
  }


  $main="
  <form action='save_class.php' method='post'>
  學年學期:<input type='text' name='seme' size='4' value='{$data['seme']}'><br>
  所屬學程:<select name='subject' size=1>
    <option value='語言與文化' $opt1>語言與文化</option>
    <option value='生命與健康' $opt2>生命與健康</option>
    <option value='社會與生活' $opt3>社會與生活</option>
    <option value='自然與環境' $opt4>自然與環境</option>
    <option value='美學與藝術' $opt5>美學與藝術</option>
    <option value='資訊與傳播' $opt6>資訊與傳播</option>
    <option value='台江分校' $opt7>台江分校</option>
    <option value='台江大廟興學' $opt8>台江大廟興學</option>
  </select>
  <br>
  班級名稱:<input type='text' name='class_name' size='30' value='{$data['class_name']}'><br>
  講師名稱:<input type='text' name='teacher' size='10' value='{$data['teacher']}'><br>
  管理密碼:<input type='text' name='passwd' size='10' value='{$data['passwd']}'><br>
  是否開放:
  <input type='radio' name='access' value='1' id='show' $radio1><label for='show'>開放</label>
  <input type='radio' name='access' value='0' id='hide' $radio0><label for='hide'>隱藏</label>
  <br>
  <input type='hidden' name='op' value='{$next_op}'>
  <input type='hidden' name='class_sn' value='{$class_sn}'>
  <input type='submit' value='儲存'>
  </form>";
  return $main;
}

?>

:::

搜尋

QR Code 區塊

https%3A%2F%2Ftad0616.cp27.secserverpros.com%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbdsn%3D549%26tbsn%3D20

書籍目錄

展開 | 闔起

線上使用者

560人線上 (130人在瀏覽線上書籍)

會員: 0

訪客: 560

更多…