溫瑞烘老師的教學歷程檔案(Teaching ePortfolio) - 104-1-資料庫程式設計-進階 - 第5週-網站統計與網站列表
 

資訊管理系
副教授
温瑞烘


歷程檔案 Portfolio


關於我 About Me

第5週-網站統計與網站列表


網站統計要列出每一個班級名稱、該班總人數、已經建置的網站數與建置百分率


班級名稱總人數網站數建置率
四技資管一乙1000 %
四技資管一丙500 %
四技資管二甲10110 %
四技資管二乙1000 %
四技資管二丙1000 %
四技資管三甲1000 %
四技資管三乙1000 %
四技資管三丙1000 %
四技資管四甲1000 %
四技資管四乙1000 %
四技資管四丙1000 %
四技資管一甲100 %



提示
epclass                               
  class_no       CHAR(6)     COMMENT  '班級代碼',
  class_name     VARCHAR(20) COMMENT  '班級名稱',
要列出每一個班級名稱的SQL
select * from epclass order by class_no

epstmd                               
  depart_class   CHAR(6)     COMMENT  '班級代碼',
  student_no     CHAR(9)     COMMENT  '學號',
  password       VARCHAR(20) COMMENT  '密碼',
  gender         CHAR(1)     COMMENT  '1:男 2:女',
  student_name   VARCHAR(20) COMMENT  '姓名',
  address        VARCHAR(60) COMMENT  '地址',
要計算某一個班的總人數 SQL
select count(*) as smdt_cnt from epstmd where depart_class='$class_no'

epweb
  oid          INT(11) NOT NULL AUTO_INCREMENT COMMENT '識別碼與顯示路徑',
  uid          VARCHAR(10) NOT NULL COMMENT '身分證 學號',
  webtitle     VARCHAR(255) NOT NULL COMMENT '網站Title',
  headoid      INT(3) NOT NULL COMMENT 'header oid ',
  content      TEXT NOT NULL COMMENT '網站內容',
要計算某一個班的網站數SQL
select count(*) as web_cnt from epweb,epstmd,epclass where
  depart_class='$class_no' and class_no=depart_class and uid=student_no


整體結構如下
<?php
  include "epconfig.php";
  echo "<html><head><title>各班網站統計</title>
        <link rel='stylesheet' type='text/css' href='style.css'>
        </head><body><table>
        <tr class='alt1'><td>班級名稱</td><td>總人數</td><td>網站數</td>
        <td>建置率</td></tr>";
  $sql="select distinct class_no,class_name from epclass order by class_no";
  $result=mysqli_query($conn,$sql);
  $cnt=0;
  while ($myrow=mysqli_fetch_array($result)) {
    $class_no=$myrow["class_no"];
    $class_name=$myrow["class_name"];
    // 依據 $class_no計算該班學生人數 select count(*) as stmd_cnt from epstmd where ......
    // $stmd_cnt為該班學生人數
    // 再依據 $class_no計算該班網站數  select count(*) as web_cnt from epweb,epstmd,epclass where ......
    // $web_cnt為該班網站數
 
    $percent=$web_cnt/$stmd_cnt*100;
    $bg=$cnt % 2 + 2;
    echo "<tr class='alt$bg'><td>$class_name</td><td>$stmd_cnt</td><td>$web_cnt</td>
          <td>$percent %</td></tr>";
    $cnt++;   
  }
  echo "</body></html>";

?>

網站列表格式

四技資管一乙 
四技資管一丙 
四技資管二甲 
    10214D001 林姿
四技資管二乙 
四技資管二丙 
四技資管三甲 
四技資管三乙 
四技資管三丙 
四技資管四甲 
四技資管四乙 
四技資管四丙
四技資管一甲 

提示

先查詢每一個班級
selec * from epclass order by class_no

以迴圈取出每一個班級
再列出已經建置的網站
select student_no,student_name,epweb.* from epstmd,epweb where depart_class='$class_no' and uid=student_no order by student_no

 echo "<a href='./epdisp.php?oid=$weboid' target='_blank'>$student_no $student_name</a><br>";     

epdisp.php是顯示網站的程式

整體結構如下 
<?php
  include "epconfig.php";
  $spaces="&nbsp;&nbsp;&nbsp;&nbsp;";
  echo "<html><head>
            <link rel='stylesheet' type='text/css' href='style.css'>
            </head><body>";
  $sql="select distinct class_no,class_name from epclass order by class_no";
  $result=mysqli_query($conn,$sql);
  while ($myrow=mysqli_fetch_array($result)) {
    $class_no=$myrow["class_no"];
    $class_name=$myrow["class_name"];
    echo "$class_name<br>";
    // 查詢該班已建好的網站
    $sql2 ="select student_no,student_name,epweb.* from epstmd,epweb where ...... ";
    $result2=mysqli_query($conn,$sql2);
    while ($myrow2=mysqli_fetch_array($result2)) {
      $student_no=$myrow2["student_no"];
      $student_name=$myrow2["student_name"];
      $weboid=$myrow2["oid"];
      $webtitle=$myrow2["webtitle"];
      echo "$spaces";
      echo "<a href='./epdisp.php?oid=$weboid' target='_blank'>$student_no $student_name</a><br>";    
    }
  }
  echo "</body></html>";

?>





 

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


文章分類 Labels

 


最新文章 Top10

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