[MYSQL/PHP/HTML]课表查询

项目目前向外招募有相关技能的小伙伴,有意者在下方评论即可。


即将更新(V2.2):

  1. 增加智能时间判断,当天课程优先显示此时段的课程,明显标注下个时段的课程,淡化已经结束的课程;
  2. 优化操作逻辑,查询后自动检测查询结果,查询成功后直接显示课程信息,不需要再手动进行确认;
  3. 添加更多课程表并进行测试;
  4. 设计UI界面用于快速添加/修改课程数据库,后期将开放权限使用户能够添加自己的课程表;
  5. 开发更多前端软件(包括但不限于微信小程序,安卓及IOS APP),最终实现客户端全平台化;
  6. 源代码优化及更新。

2019-06-13(V2.1.9):

  1. 更新课程时间数据,现已支持每天5节课;
  2. 小程序体验版已发布;
  3. 数据库数据更新;
  4. 修复接口BUG及更新造成的错误;
  5. 增加【劳动节】调休信息;

11-09(V2.1.8):

  1. 提升PHP版本为7.2。

10-28(V2.1.7):

  1. 修复实验课程数据问题。

10-01(V2.1.6):

  1. 再次修复课程排序问题。

09-26(V2.1.5):

  1. 更正【数据库】信息以适配实验课;
  2. 新增【重修】课程信息,目前仅可自用,后续将开放用户自定义接口。

09-24(V2.1.4):

  1. 更新【国庆节】调休信息;
  2. 修复表格显示逻辑出错的问题,现在课程表格已经可以正常显示;
  3. 接口返回值出错问题已解决,所有服务恢复正常。

09-23(V2.1.3):

  1. 修复日期非法造成的一系列问题,由于使用的接口只能查询一个自然年的假期,故对查询日期进行限制(从2018-09-03至2018-12-31,后续将设置更适合的操作逻辑并对限制进行解除);
  2. 修复调休默认为周五的bug(默认为周三,如果有具体通知将及时更新查询系统,后期将进行优化);
  3. 同步更新课程源[B电子162],查询系统已更新至v2.1.3;
  4. 源代码更新至最新。

09-19(V2.1.?):

  1. 新增Today查询方式,最终效果可接入IOS系统中Siri实现语音查询课程效果(由于操作逻辑问题,暂未实现),Today方式默认查询今天的课程,并直接显示在网站中部。

09-18(V2.1.2):

  1. 修复多次查询时检测结果失效导致的一系列显示问题。

09-17-2(V2.1.1):

  1. 增加课程源:B电子162

09-17(V2.1):

  1. 修复调休显示异常的问题;
  2. 优化快捷通知栏显示效果;
  3. 修改再次查询时页面刷新逻辑,现在无须等待页面刷新即可再次查询并且记录上一次日期的选择;
  4. 课程表格移除“课程编号”列,将“起止时间”列更改为“备注”,显示更加清晰。

09-15(V2):

  1. 重新设计了数据库[上课时间数据对]的存储方案,课程时间问题已经完全修复;
  2. 本网站(https://niit.weyoung.tech)的查询系统所依赖的数据库迁移至本服务器上,目前访问速度提升明显,已经没有明显的等待时间;
  3. 网页打开时默认日期设置为今日,后期将加入更合理的逻辑判断;
  4. 加入快捷通知栏,可以直接看到例如调课、调休或即将到来的节假日等信息(暂未实现);
  5. 源代码更新至最新。

09-14:

  1. 重新申请单个域名证书,APP以及绝大多数主流浏览器已经不会报错。

09-13:

  1. 数据库更新,调整课程序号(调课)。

2018-09-09(V1):

  1. 课程表查询系统(https://niit.ikouane.top/mysql/index.html)发布。

测试效果(V1):


源代码(V2):

1.class.php

<?php
header("Content-Type: text/html;charset=utf-8");
ini_set("error_reporting","E_ALL & ~E_NOTICE");
function diffBetweenTwoDays ($day1, $day2)
{
  $second1 = strtotime($day1);
  $second2 = strtotime($day2);
   
  if ($second1 < $second2) {
    $tmp = $second2;
    $second2 = $second1;
    $second1 = $tmp;
  }
  return ($second1 - $second2) / 86400;
}
$date=$_POST['date'];
$recode=0;
//跨//$weeknum="所选时间是今年第".date('W',strtotime($date))."周<br/>";
//年//echo $weeknum;
//失//$weekn=date('W',strtotime($date))-date('W',strtotime('2018-09-03'))+1;
//效//echo "所选时间是开学第".$weekn."周<br/>";
$weekn=floor(diffBetweenTwoDays($date,"2018-09-03")/7)+1;
//echo $weekn;开学第N周检测
$lejson ="";
$n=1;
$js=0;
$weekarray=array("日","一","二","三","四","五","六");
$weekarrayc=array("日","一","二","三","四","五","六");
$weekarraye=array("7","1","2","3","4","5","6");
//echo "星期".$weekarray[date("w",strtotime($date))];日期星期N检测
switch ($weekarray[date("w",strtotime($date))])
{
  case "一":
    $weekday="1";
    break;
  case "二":
    $weekday="2";
    break;
  case "三":
    $weekday="3";
    break;
  case "四":
    $weekday="4";
    break;
  case "五":
    $weekday="5";
    break;
  case "六":
    $weekday="6";
    break;
  case "七":
    $weekday="7";
    break;
  default:
    $weekday="null";
}
  $ch = curl_init();
    $url ='http://lanfly.vicp.io/api/holiday/info/

2.index.html
.$date;
    $pdate = preg_replace('/[-]+/i','',$date);
  $surl= 'http://api.goseek.cn/Tools/holiday?date='.$pdate;
  $result = file_get_contents($url);
    $sresult = file_get_contents($surl);
    $arr = json_decode($result);
  $sarr = json_decode($sresult);
    //echo $result."<br/>".$sresult."<br/>";接口结果输出检测
  if($sarr->data=='2'){
  $sta = $arr->holiday->holiday;
  $honame = $arr->holiday->name;
  if($sta){
     $recode=2;
      //echo "节假日信息:".$honame;
     $weekday="/";
    }
  else
   {
    if ($honame==""){
      
    //echo "不是节假日!";
    }
      //else $recode=-1;//echo "调休信息:".$honame;
   }
    }
else{
  if($sarr->data=='1') {$recode=1;$honame="双休日";}//echo "双休日!今天不上课!";
  if($sarr->data=='0'){
    if($arr->holiday<>null){
    $sta = $arr->holiday->holiday;
  $honame = $arr->holiday->name;
      switch ($pdate)
      {
        case "20180929":
          $weekday="3";
        break;
        case "20180930":
          $weekday="4";
        break;
        default:
        //echo "<br/>没有调休信息,默认按礼拜三补课!";默认调休信息检测
        $weekday="3";
        break;
      }
      //echo "调休信息:".$honame."(补周".$weekday.")的课";调休信息检测
      $recode=-1;
    }
    else {$recode=0;$honame="工作日";}//echo "工作日!今天要上课!今天要上课!今天要上课!<br/>";
  }
}
$con = mysql_connect("数据库地址","用户名","密码");
if (!$con)
  {
  die('数据库连接失败: ' . mysql_error());
  }

mysql_select_db("数据库名", $con);

$result = mysql_query("SELECT * FROM 课程表_new WHERE 上课时间数据对 LIKE '%".$weekarrayc[$weekday].",%' OR 上课时间数据对 LIKE '%0,%' ORDER BY MID( substring_index( 上课时间数据对, '".$weekarray[date("w",strtotime($date))]."',- 1 ), 2, 1 )");

/*echo "<table border='1'>
<tr>
<th>课程编号</th>
<th>课程名</th>
<th>任课教师</th>
<th>上课地点</th>
<th>上课时间</th>
<th>起止时间</th>
</tr>";*///表格head打印

while($row = mysql_fetch_array($result))
{
$sjsz = explode(';',$row['上课时间数据对']);
$sjdd = explode(',',$row['上课地点数据对']);
$sjqz = explode(',',$row['课程起止数据对']);
$sjqzstart=$sjqz[0];
$sjqzend=$sjqz[1];
//echo $sjqzstart."-".$sjqzend;//起止时间输出检测
for($index=0;$index<count($sjsz);$index++) 
{
$js=0;
//echo $sjsz[$index];echo "</br>";上课时间数据对拆分输出检测
if ($sjd=strstr($sjsz[$index],$weekarrayc[$weekday] .',')){
$js=$js+1;
//echo "(".$index.")".$sjdd[$index];
  if($sjdd[$index]==""){
  $row['上课地点数据对']= $sjdd[0];
}
  else $row['上课地点数据对']= $sjdd[$index];
//echo $row['上课地点数据对'];
//echo $sjsz[$index]."<hr>";
$nob = substr($sjd,-1);
//echo $nob."<br/>";时间序号输出检测
$row['上课时间数据对']=$nob;
//echo $nob."<br/>";
//echo $row['上课时间数据对'];
     switch ($row['上课时间数据对'])
    {
    case 0:
      $row['上课时间数据对']="整个上午";
      break;
    case 1:
      $row['上课时间数据对']="08:00-09:40";
      break;  
    case 2:
      $row['上课时间数据对']="10:00-11:40";
      break;
    case 3:
      $row['上课时间数据对']="14:00-15:40";
      break;
    case 4:
      $row['上课时间数据对']="16:00-17:40";
      break;
    case 5:
      $row['上课时间数据对']="19:00-20:40";
      break;
    default:
      $row['上课时间数据对']="整天上课";
    }
}
  //echo "(".$js.")";
}
  if ($weekn >= $sjqzstart && $weekn <= $sjqzend){
  //echo $row['课程名'].$row['上课时间数据对']."<br/>";
  /*echo "<tr>";
  echo "<td>" . $row['课程编号'] . "</td>";
  echo "<td>" . $row['课程名'] . "</td>";
  echo "<td>" . $row['任课教师'] . "</td>";
  echo "<td>" . $row['上课地点数据对'] . "</td>";
  echo "<td>" . $row['上课时间数据对'] . "</td>";
  echo "<td>" . $row['课程起止数据对'] . "</td>"; 
  echo "</tr>";*///输出结果检测【表格】
  //$lejson="{"lesson1": {"no": "0007021031-02","name": "汇编语言程序设计","place": "博学楼1J1B203","time": "14:00-15:40"},"lesson2": {"no": "0007022262-01","name": "NIIT-3","place": "博学楼1J1D210","time": "16:00-17:40"}}";
   $lejson=json_encode(array('课程编号' => $row['课程编号'], '课程名' => $row['课程名']  ,'任课教师' => $row['任课教师'] ,'上课地点' => $row['上课地点数据对'], '上课时间' => $row['上课时间数据对'], '起止时间' => $row['课程起止数据对'] ),JSON_UNESCAPED_UNICODE);
   //$lejson =  $lejson."lesson".$n.":{".json_encode(array('课程编号' => $row['课程编号'], '课程名' => $row['课程名'] ,'上课地点' => $row['上课地点'], '上课时间' => $row['上课时间数据对'], '起止时间' => $row['课程起止数据对'] ),JSON_UNESCAPED_UNICODE)."}";
   $lejson = "\"lesson".$n."\":".$lejson.",";
   $lesjson = $lesjson.$lejson;
   $n=$n+1;
  }
  }
//echo $lesjson;课程JSON检测
if ($recode>0){
  $lesjson="{\"code\":\"".$recode."\","."\"holiday\":\"".$honame."\","."\"weekn\":\"".$weekn."\","."\"weekday\":\"".$weekarrayc[date("w",strtotime($date))]."\"}";
}
else{
  if ($recode==-1){
    $lesjson="{\"code\":\"".$recode."\","."\"holiday\":\"".$honame.",补周".$weekday."的课"."\","."\"weekn\":\"".$weekn."\","."\"weekday\":\"".$weekarrayc[date("w",strtotime($date))]."\",".substr($lesjson,0,-1)."}";
  }
  else{
$lesjson="{\"code\":\"".$recode."\","."\"holiday\":\"".$honame."\","."\"weekn\":\"".$weekn."\","."\"weekday\":\"".$weekarrayc[date("w",strtotime($date))]."\",".substr($lesjson,0,-1)."}";}
}
if($weekn>19) {$lesjson="{\"code\":\"2\","."\"holiday\":\"长假\","."\"weekn\":\"".$weekn."\","."\"weekday\":\"".$weekarrayc[date("w",strtotime($date))]."\"}";}
//echo "<b>".$lesjson."</b>";返回值JSON检测
echo $lesjson;
//echo "</table>";表格输出
//echo "返回值示例";
mysql_close($con);
?>

2.index.html

<!DOCTYPE HTML>
<!-- 原作者信息:
  Overflow 1.0 by HTML5 UP
  html5up.net | @n33co
  Free for personal and commercial use under the CCA 3.0 license (html5up.net/license)
  第二作者信息:
    WeYounG.tech | @IKOUANE
  Free for personal and commercial use under the CCA 3.0 license
-->
<html>
  <head>
    <title>课表查询</title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <meta name="description" content="" />
    <meta name="keywords" content="" />
        <link rel="shortcut icon" href="https://weyoung-oss.oss-cn-shanghai.aliyuncs.com/%E5%9B%BE%E7%89%87/WYG-DG.png"> 
    <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,300italic" rel="stylesheet" type="text/css" />
        <script src="js/jquery-2.2.4.min.js" type="text/javascript"></script>
      <script src="js/json2.js" type="text/javascript"></script>
      <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css">
    <script>
     timer=setTimeout(function() { $("#topbar").slideUp();$("#tophead").slideUp(); }, 10000);
    </script>
    <script>
      $(document).ready(function(){
      $("#topbar").click(function(){
      $("#topbar").toggle( "slide" );
      $("#tophead").html("显示");
      $("#tophead").width(60);
      $("#tophead").css("color","white");
      clearTimeout(timer);
      });
      $("#tophead").click(function(){
      $("#topbar").toggle( "slide" );
      $("#tophead").html("!");
      $("#tophead").width(6);
      $("#tophead").css("color","#3498db");
      clearTimeout(timer);
      });
      });
  </script>

        <script>
          var code,lesson,holiday,weekday,weekn;
          var parsedJson,lessondata;
          function check(){
           $("#banner").show();
           //$("#banner").fadeToggle();
          //document.getElementById("banner").style.visibility="visible";
          var date=document.getElementById("date").value;
          //if (date=='null')  alert("日期非法!");//$("topbar").text("请选择日期!");
            
          //date = date.split("-").join("");
         //alert(date);
         /*var url ='http://lanfly.vicp.io/api/holiday/info/
.$date;*/
          $.post('class.php',{"date":date},function(data,status){
          if(status=='success'){//这里返回的success表示请求成功,单不表述你的逻辑处理成功
           $("#next").show();
           //document.getElementById("next").style.visibility="visible";       
          parsedJson = jQuery.parseJSON(data);
          code = parsedJson.code;
          holiday= parsedJson.holiday;
          weekday=parsedJson.weekday;
          weekn=parsedJson.weekn;
          /*switch(code)
            {
            case '1':
              code="双休日";
              break;
            case '2':
              code="节假日";
              break;
            case '0':
              code="工作日";
              break;
            case '-1':
              code="节假日调休";
              break;
            default:
              code="异常!"
              break;
            }*/
            if (code>0) 
            {
             document.getElementById("tb").style.display="none";
             document.getElementById("htitle").innerHTML="今天不上课哦!";
            }
            if (weekn>19) { 
              document.getElementById("tb").style.display="none";
              document.getElementById("htitle").innerHTML="学期已结束!假期愉快!";
              document.getElementById("info").innerHTML=date + ",周"+ weekday + "(长假)" +",本学期已结束!";}
            else{
           document.getElementById("info").innerHTML=date + ",周"+ weekday + "("+ holiday + ")" +",本学期的第"+weekn+"周,共19周";}
        //alert(parsedJson);
        //alert(data);
        //alert(data.substring(0, data.indexOf('lesson1')));
         var slast=data.substring(data.indexOf('lesson1') + 1, data.length);
           lessondata="{\"l"+slast;
          }
           else{
          alert('服务器处理失败');
          }
          });
          }
          function formvisiable(){
          $("#form").show();
          //$("#form").fadeToggle();
          //document.getElementById("form").style.visibility="visible";
     if(code<=0){
    var lessondatap = lessondata.replace("\"lesson1\":","");
            lessondatap = lessondatap.replace("\"lesson2\":","");
              lessondatap = lessondatap.replace("\"lesson3\":","");
                lessondatap = lessondatap.replace("\"lesson4\":","");
     //alert(lessondatap);
   
    lessondatap=lessondatap.substr(0,lessondatap.length-1);
    lessondatap=lessondatap.substr(1,lessondatap.length-1);
    //lessondatap = toString(lessondatap);
    lessondatap = "["+lessondatap+"]";
    //alert(lessondatap);
    lessondatap = jQuery.parseJSON(lessondatap);
    var datanav = lessondatap;//jQuery.parseJSON(lessondata);
    var tb = document.getElementById("tb");
    for (var i = 0; i < lessondatap.length; i++) {
        var row = tb.insertRow(tb.rows.length);
        var c1 = row.insertCell(0);
        c1.innerHTML = datanav[i].课程名;
        //var c2 = row.insertCell(1);
        //c2.innerHTML = datanav[i].课程编号;
        var c3 = row.insertCell(1);
        c3.innerHTML = datanav[i].任课教师;
        var c4 = row.insertCell(2);
        c4.innerHTML = datanav[i].上课地点;
        var c5 = row.insertCell(3);
      if (datanav[i].上课时间=="0,0") c5.innerHTML = "全周上课";
      else c5.innerHTML = datanav[i].上课时间;
      //var timearr = datanav[i].上课时间.split("-");
      //alert("Start:"+timearr[0]+"End:"+timearr[1]);
        var c6 = row.insertCell(4);
        c6.innerHTML = datanav[i].起止时间+"周";
}
      }
          }
        </script>
         <script type="text/javascript">
           function shuaxin(){
             $("#tb  tr:not(:first)").html("");
              $("#banner").fadeToggle("slow");
              $("#form").fadeToggle("slow");
              $("#next").fadeToggle();
             // window.location.reload();
            }
      </script>
    <!--[if lte IE 8]><script src="css/ie/html5shiv.js"></script><![endif]-->
    <script src="js/jquery.min.js"></script>
    <script src="js/jquery.poptrox-2.2.js"></script>
    <script src="js/skel.min.js"></script>
    <script src="js/init.js"></script>
    <noscript>
      <link rel="stylesheet" href="css/skel-noscript.css" />
      <link rel="stylesheet" href="css/style.css" />
    </noscript>
    <!--[if lte IE 8]><link rel="stylesheet" href="css/ie/v8.css" /><![endif]-->
        <style>
          #totop{
          background-color:rgb(22, 160, 133);
          }
          #form{
          width:75%;
          }
          #lessonform{
          }
          th{
          border-bottom:2px solid rgb(52, 73, 94);
          vertical-align: middle;}
          td{
            border-bottom:1px dashed rgb(52, 73, 94);
             vertical-align: middle;
          }
          #tb tr td{
            text-align:center;
             vertical-align: middle;
          }
          #tb tr th{
            font-size:30px;
            font-weight:bold;
            vertical-align: middle;
          }
          #topbar{           
            position:fixed;
            top:0px;
            margin:0px;
            padding:0px;
            width:100%;
            text-align:center;
            background-color:white;
            z-index:9;
            font-size:16px;
          }
          #tophead{           
            position:fixed;
            top:0px;
            margin:0px;
            padding:0px;
            text-align:center;
            background-color:#3498db;
            color:#3498db;;
            z-index:11;
            width:6px;
            font-size:10px;
          }
      </style>
  </head>
  <body>
    <!-- Header -->
    <div id="tophead">!</div>
    <div id="topbar">当前版本v2.1.3 | 数据库9/15 | 查询系统9/23 | <a target="_blank" href="https://www.weyoung.tech/mysqlphphtml_kbcx">查看更新</a></div>
      <section id="header">
        <header id="topheader">
          <h1>数据库实战[1]-课程表</h1>
          <p>By Ikouane</p>
                    <br/><br/>
                  <form action="class.php" method="post">
                 ⎛⎝≥⏝⏝≤⎠⎞ <br/><br/><br/>
                 选择一个日期吧:<input type="date" required min="2018-09-03" max="2018-12-31" name="date" id="date"/>
                </form>
                  
        </header>
        <footer>                
          <a href="#banner" class="button style2 scrolly" onclick="check()">查询</a>
        </footer>
      </section>
    
    <!-- Banner -->
      <section id="banner" style="display:none">
        <header>
          <h2>正在查询,请稍候!</h2>
        </header>
        <p>这是基于服务器端MYSQL搭建的查询平台,可在大部分流行平台使用;<br />
        使用HTML进行前端的搭建,后台使用PHP进行数据库的连接及查询;<br />
        该平台采用两条公用接口并设计算法,可精确识别所选日期的工作信息;<br />
                -欢迎访问 <a href="https://www.weyoung.tech/mysqlphphtml_kbcx">未央宫</a> 获取源代码-</p>
        <footer>
          <a href="#form" class="button style2 scrolly" styl="display:none" id="next" onclick="formvisiable();">查询完成,立即查看</a>
        </footer>
      </section>
            <div class="copyrights">Collect from <a href="http://www.cssmoban.com/" >网页模板</a></div>
    
    <!-- Contact -->
      <article id="form" class="container box style3" style="display:none">
        <header>
          <h2 id="htitle">以下是当天的课程信息</h2>
          <p id = "info"></p>
          <!--<marquee id="info" behavior="scroll" scrollamount="5" scrolldelay="1">这里是滚动通知栏</marquee>-->
        </header>
        <form id = "lessonform">
          <div class="row half">
               <table border="1" id="tb" align="center">
              <tr>
              <th>课程名</th>
              <!--<th>课程编号</th>-->
              <th>任课教师</th>
              <th>上课地点</th>
              <th>上课时间</th>
              <th>备注</th>
               </tr>
               </table>
                      
          </div>

          <div class="row">
            <div class="12u">
              <ul class="actions">
                <li><a href="#header" class="button style2 scrolly" id = "totop" onclick="shuaxin();">再次查询</a></li><!--class="button form"-->
              </ul>
            </div>
          </div>
              </form>

      </article>
    
    <section id="footer">
      <ul class="icons">
        <li><a href="#" class="icon icon-twitter solo"><span>Twitter</span></a></li>
        <li><a href="#" class="icon icon-facebook solo"><span>Facebook</span></a></li>
        <li><a href="#" class="icon icon-google-plus solo"><span>Google+</span></a></li>
        <li><a href="#" class="icon icon-pinterest solo"><span>Pinterest</span></a></li>
        <li><a href="#" class="icon icon-dribbble solo"><span>Dribbble</span></a></li>
        <li><a href="#" class="icon icon-linkedin solo"><span>LinkedIn</span></a></li>
      </ul>
      <div class="copyright">
        <ul class="menu">
          <li>&copy2017-2018; WeYounG. All rights reserved.</li>
          <li>Origin: HTML5 UP</li>
          <li> Made by <a href="https://www.weyoung.tech/" target="_blank" title="模板之家">未央宫</a></li>
        </ul>
      </div>
    </section>
  </body>
  <script type="text/javascript">
    function Appendzero(obj)
    {
        if(obj<10) return "0" +""+ obj;
        else return obj;
    }
        var mydateInput = document.getElementById("date");
        var date = new Date();
      var month=new Array(12)
        var dateString = date.getFullYear() + "-" +  Appendzero((date.getMonth() + 1)) + "-" + Appendzero(date.getDate());
        mydateInput.value = dateString;
    </script>
</html>

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注