溫瑞烘老師的教學歷程檔案(Teaching ePortfolio) - 資管三甲乙資料庫系統教學資源區 - 第十三週另一種介面
 

資訊管理系
副教授
温瑞烘


歷程檔案 Portfolio


關於我 About Me

第十三週另一種介面

第一組參考程式

<?php
  include "config.php";
  $command=$_POST["command"];
  $PHP_SELF=$_SERVER["PHP_SELF"];
  if ($command==null) {
     display_form($conn); 
  }
  if ($command=="查詢") {
    display_form($conn); 
  }
  if ($command=="新增") {
    $no=$_POST["no"];
    $student_no=$_POST["student_no"];
    $student_name=$_POST["student_name"];
    $address=$_POST["address"];
    $sql="insert into stmd values('$no','$student_no','$student_name','$address')";
    $result=mysql_query($sql,$conn);
    display_form($conn);
  }
   if ($command=="儲存") {
    $sql="delete from stmd";
    $result=mysql_query($sql,$conn);
    $cnt=$_POST["cnt"];
    for ($i=1; $i<=$cnt; $i++) {
      $no=$_POST["no$i"];
      $student_no=$_POST["student_no$i"];
      $student_name=$_POST["student_name$i"]; 
      $address=$_POST["address$i"];
      if ($no!=null && $student_no!=null) {
         $sql="insert into stmd values('$no','$student_no','$student_name','$address')";
         $result=mysql_query($sql,$conn);
      }
    }
    display_form($conn); 
  }

  function display_form($conn) {
    echo("<center><table border=1 bordercolor='#ff0000' width=100%>
          <tr><td>班級代碼</td><td>學號</td>
              <td>姓名</td><td>地址</td></tr>
          <form method='post' action='$PHP_SELF'>
          <tr><td><select name=no size=1>
         ");
    $sql_1="select * from dept order by no";
    $result_1=mysql_query($sql_1,$conn);
    while ($myrow_1=mysql_fetch_array($result_1)) {
      $no_1=$myrow_1["no"];
      $name_1=$myrow_1["name"];
      echo "<option value='$no_1'>$name_1($no_1) </option>";
    }  
    echo ("</td><td><input type=text name=student_no size=10></td>
           <td><input type=text name=student_name size=20></td>
           <td><input type=text name=address size=50></td></tr></table>
           <td><input type=submit name=command value='查詢'>
           <input type=submit name=command value='新增'></td></tr>
           </form><hr>
         ");
    $sql="select * from stmd order by no";
    $result=mysql_query($sql,$conn);
    $no_of_rows=mysql_affected_rows($conn);
    if ($no_of_rows>0) {
       $cnt=0;
       echo ("<table border=1 bordercolor='#ff0000' width=100%>
              <tr><td>班級代碼</td><td>學號</td>
                  <td>姓名</td><td>地址</td></tr>
              <form method='post' action='$PHP_SELF'>
             ");
       while ($myrow=mysql_fetch_array($result)) {
          $cnt++;
          $no=$myrow["no"];
          $student_no=$myrow["student_no"];
          $student_name=$myrow["student_name"];
          $address=$myrow["address"];
          echo ("<tr><td><input type=text name='no$cnt' value='$no' size=10 ></td>
                 <td><input type=text name='student_no$cnt' value='$student_no' size=10></td>
                 <td><input type=text name='student_name$cnt' value='$student_name' size=20></td>
                 <td><input type=text name='address$cnt' value='$address' size=50></td></tr>
               ");
       }
       echo "</table><input type=submit name=command value='儲存'>
             <input type=hidden name=cnt value='$cnt'>";
    }
  }
?>
 


第一組:參考前面範例 寫一程式作學生基本資料的 新增 查詢 儲存(含更新及刪除) 其中班級代碼使用下拉選單

第二組 參考學生基本資料檔 利用網路 或書籍 回答下列問題 (下課時交紙本作業)
1. 查尋所有欄位 條件為學號 等於 "9714D001"者
2. 查尋所有欄位 條件為學號 大於 "9714D001"者
3. 查尋所有欄位 條件為學號 中有 "4D"者
4. 查尋所有欄位 條件為學號 中沒有 "4D"者
5. 查尋所有欄位 條件為學號 中沒有 "4D"者 按學號由大至小排列
6. 更新學號欄位為"9714D010"  條件為學號 等於 "9714D001"者
7. 更新學號欄位為"9714D010",班級代碼為"164D32"  條件為學號 等於 "9714D001"者
8. 刪除列 條件為學號等於 "9714D001"者
9. 刪除列 條件為學號等於 "9714D001",班級為"164D21"者
10. 刪除列 條件為學號中有 "4D"者
 

全部共 0則留言
登入帳號密碼代表遵守學術網路規範
 


文章分類 Labels

 


最新文章 Top10

中華科技大學數位化學習歷程 - 意見反應