:::

10-1 上課範例:index.php

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

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

//流程控制
if($op=="delete"){
  //若op是刪除班級,則呼叫刪除班級函數
  delet_class($class_sn);
}else{
  //否則執行列出班級函數
  $main=list_class();
}

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

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

//刪除班級
function delet_class($class_sn=null){

  //設定SQL語法
  $sql="delete from `tncomu_class` where class_sn='{$class_sn}'";

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

  //執行完轉向
  header("location: index.php");
}

//列出所有班級
function list_class(){
  //設定SQL語法
  $sql="select * from `tncomu_class`  order by seme desc, subject";

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

  $main="
  <script>
  function delete_func(sn){
   var sure = window.confirm('確定要刪除此資料?');
   if (!sure)	return;
   location.href='index.php?op=delete&class_sn=' + sn;
  }
  </script>
  
  <table border=1>";
  
  while($data=mysql_fetch_assoc($result)){
    $main.="
    <tr>
    <td>{$data['class_sn']}</td>
    <td>{$data['seme']}</td>
    <td>{$data['subject']}</td>
    <td>{$data['class_name']}</td>
    <td>{$data['teacher']}</td>
    <td>{$data['passwd']}</td>
    <td>{$data['access']}</td>
    <td><a href='java_script:delete_func({$data['class_sn']})'>刪除</a> | <a href='add_class.php?class_sn={$data['class_sn']}&op=edit'>編輯</a></td>
    </tr>";
  }
  
  $main.="</table>";
  
  return $main;
}

?>

:::

搜尋

QR Code 區塊

https%3A%2F%2Ftad0616.net%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbdsn%3D548%26tbsn%3D20

書籍目錄

展開 | 闔起

線上使用者

50人線上 (22人在瀏覽線上書籍)

會員: 0

訪客: 50

更多…