溫瑞烘老師的教學歷程檔案(Teaching ePortfolio) - PHP教學 - 以PHP查尋MySQL範例
 

資訊管理系
副教授
温瑞烘


歷程檔案 Portfolio


關於我 About Me

以PHP查尋MySQL範例

<?php
 include "config.php";
  $command=$_POST["command"];
  if ($command==null) {
   echo("
         <html>
         <title>MySql 查詢範例</title>
         <center>
         <form method='post' action=$PHP_SELF>
         <table border=0>
         <tr>
         <td>學號:</td>
         <td>
         <input type='text' name='student_no' size='9'>
         </td>
         </tr>
         </table>
         <input type='submit' name='command' value='新增'>
         <input type='submit' name='command' value='查詢'>
         <input type='reset'  name='command' value='清除 '>        
         </form>
         </center>
         </html>
        ");
 }
 if ($command=="查詢") {
   $student_no=$_POST["student_no"]; // 以學號為鍵值查詢
   if ($student_no==null || $student_no=="") $student_no="%"; // 查詢全部
   // 準備 SQL 查詢命令
   $sql="select * from stmd where student_no like '$student_no' order by student_no";
   $result=mysql_query($sql,$conn);        // SQL命令執行
   $no_of_rows=mysql_affected_rows($conn); // 影響列數
   if ($no_of_rows>0) {                    // 查詢成功
     echo("<html><body><center>");
     while ($myrow=mysql_fetch_array($result)) {  // 取出一列
       $student_no=$myrow["student_no"];          // 取出欄位
       echo $student_no ."<br>";                  // 顯示資料
      }
     echo("</center></body></html>");
   }
 }
 ?>

 

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


文章分類 Labels

 


最新文章 Top10

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