Born to be proud
10/13
2014

成绩查询系统

学校的成绩查询系统是没有排名与加权平均分的,9月份正巧在看PHP,便萌生了写个小的查询系统的想法,中间又感觉意义用途不大,停了一段时间想着算了不做了,周日闲的没事,又看了看,顺手把界面写了一下,差不多也完成了,过程也算是个练手。核心原理就是通过正则表达式查找csv文件,进行输出。还存在几个Bug,就这样吧。
演示地址:http://cj.liu13.com

collage.jpg


下面是源代码,一共两个文件:
index.php

<html>
<?
#########################程序简介##########################
#程序名称:成绩查询系统
#版本:       v1.0
#作者:    刘十三
#邮箱:    liu13@liu13.com   
#主页:    http://www.liu13.com
?>
<head>
    <title>成绩查询</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <style type="text/css">
        body {background:#eee;}
        ul {padding:0; margin:0;}
        li {list-style:none;}
        #container {margin: 0 auto; width: 80%;}
        #title {color:#146fdf;font-size:25px; text-align:center; font-family:"YouYuan"; font-weight:bold;margin-top:40px;}
        a {color:#146fdf; text-decoration: none}
        a:hover {color: black; text-decoration: underline}
        #g_list {margin-top:60px; background:#fff;height:89px;border-radius:4px}
        #g_u,#g_p {position:relative}
        #g_u {border-bottom:1px solid #eaeaea}
        .inputstyle {text-align:center;-webkit-tap-highlight-color:rgba(255,255,255,0); width:100%; height:44px;color:#000;border:0; background:0; font-size:16px;-webkit-appearance:none}
        #cjsubmit {margin-top:40px; width:100%; height:44px; color:#146fdf}
        .button {border:0px; width:100%; height:100%;color:white; background:#146fdf; border-radius:4px; font-size:16px;}
        #notice {text-align:center; margin-top:60px; color:#246183; line-height:14px; font-size:14px; padding:15px 10px}
    </style>
</head>
<body>
    <div id="container">
        <div id="title">成绩查询</div>  
            <form method=post name="cf" target="_blank" onSubmit=javascript:chkfs()>
                <ul  id="g_list">
                    <li  id="g_u">
                        <div  id="del_touch"  class="del_touch">
                            <span  id="del_u"  class="del_u"  style="display: none;"></span>
                        </div>
                        <input  id="u"  class="inputstyle"  name="pname"  autocomplete="off"  placeholder="请输入姓名">

                    </li>
                    <li  id="g_p">
                        <div  id="del_touch_p"  class="del_touch">
                            <span  id="del_p"  class="del_u"  style="display: none;"></span>
                        </div>
                        <input  id="p"  class="inputstyle"  maxlength="10"  name="pnum"  autocorrect="off"  placeholder="请输入学号">

                    </li>
                </ul>
            <div id="cjsubmit"><input type=submit value=查分 class="button"></div>
            <script language=javascript>  
                function chkfs(){ 
                var frm = document.forms['cf'];  
                frm.action="search.php";
                return true;  
                }
            </script>
        </form>

        <div id="notice">
            仅支持计算机与信息工程学院2013级计科专业学生查询<BR>
            如果出现结果有误,请先仔细检查您输入的考号或姓名是否正确!<BR>
        <p align=center>
            Powered by <a href=http://weibo.com/liu133>刘十三</a>
        </div>
    </div>
</body>
</html>

search.php

<html>
<?
#########################程序简介##########################
#程序名称:成绩查询系统
#版本:       v1.0
#作者:    刘十三
#邮箱:    liu13@liu13.com   
#主页:    http://www.liu13.com
#运行环境:任何支持PHP的空间,PHP的版本不小于4.0.0
$numerror="<font size=4 color=red>请您正确输入学号!</font>";            //考号格式输入错误时的信息
$nonumkey="<font size=4 color=red>请输入您的学号!</font>";              //无输入学号时提示
$nameerror="<font size=4 color=red>请您输入正确的姓名!</font>";            //姓名格式输入错误时的信息
$nonamekey="<font size=4 color=red>请输入您的姓名!</font>";                  //无输入时提示
$notmatch="<font size=4 color=red>学号与姓名不匹配!</font>"                //学号姓名不匹配
?>
<head>
    <title>成绩查询</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <style type="text/css">
    #title {color:#146fdf;font-size:25px; text-align:center; font-family:"YouYuan"; font-weight:bold;margin-top:40px;margin-bottom:30px;}
    body {background:#eee;}
    #container {margin:0 auto; width: 80%;}
    a {color:#146fdf; text-decoration: none}
    a:hover {color: black; text-decoration: underline}
    .button {border:0px;width:100%; height:100%; color:white; background:#146fdf; border-radius:4px; font-size:16px;}
    #closewindos {margin-top:60px; width:30%; height:30px; color:#146fdf}
    #notice {text-align:center; margin-top:60px; color:#246183; line-height:14px; font-size:14px; padding:15px 10px}
    table {border:1px solid #eaeaed;}
    td {font-size:20px;border-bottom:1px solid #eaeaed; color:#246183}
    </style>
</head>
<body>
    <div id="container">
        <center>
        <div id="title">成绩查询</div>
        <?
        error_reporting(0);  //禁用错误报告

        $nl="4";
        $nameerr="<font size=4 color=red>$nameerror</font>";
        if($_POST[pname]=="") echo $nonamekey;     
        elseif (eregi("[<>() ,#|;%/$1234567890\abcdefghijklmnopqrstuvwxyz]",$_POST[pname])) echo $nameerr;
        elseif (strlen($_POST[pname])<$nl) echo $nameerr;    //检查输入姓名是否合法

        $numerr="<font size=4 color=red>$numerror </font>";
        if($_POST[pnum]=="") echo $nonumkey;     
        elseif (strlen($_POST[pnum])!=10) echo $numerr;
        elseif (eregi("[0123456789]",$_POST[pnum]))    //检查输入学号是否合法
        {
        $db = "data.csv";   //csv数据文件           
        $querydb = file($db);
        $count = count($querydb);
        for($i=0; $i<$count; $i++) {
        $detail = explode(",",$querydb[$i]);
        $keyword = explode(" ",$_POST[pnum]);
        $querycount = count($keyword);
        $tds = explode(",",$querydb[1]);
        for ($ai=0; $ai<$querycount; $ai++) 
        {eval("\$foundnum = eregi(\"$keyword[$ai]\",\"$detail[0]\");");}  
        if($_POST[pname] == $detail[1]) $match = 1;  //索引学号
        else $match = 0;

        if($foundnum && $match == 0) echo $notmatch;   //匹配姓名学号
        if($foundnum && $match)
        {
        $arrlength=count($tds);
        echo"<font color=red size=4>$detail[1]童鞋<br>您在计科专业的排名为<br>
            <font color=#146fdf size=40>$detail[3]</font>
            <br>您的加权平均分为$detail[2]
            <br>击败了$detail[4]的童鞋</font>
            <br><br><br><font color=#246183>您的各科成绩如下</font>";
        echo"<table>";
        for($i=5;$i<$arrlength;$i++)
        {
        if($detail[$i]!=""){
        echo"<tr><td>$tds[$i]</td>
                  <td>$detail[$i]</td></tr>";}}
        echo"</table>";break;
        }}}
        ?>
        <div id="closewindos"><input type="button" value="关闭此页" class="button" onClick="javascript:window.close()"></div>
        </center>
        <div id="notice">
        <p align=center>Powered by <a href=http://weibo.com/liu133>刘十三</a>
        </div>
    </div>
</body>
</html>