PHP开发一个简单的成绩录入系统

时间:2024-02-22 08:45:11

预览界面

源码:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style type="text/css">
        table{
            text-align: center;
        }
    </style>
</head>
<body>
    <form action="" name="number" method="post">
        Input the number of student:&nbsp;
        <input type="number" name="stuNum"/>&nbsp;
        <input type="submit" value="OK" name="submitStu"/>
    </form>
</body>
</html>

<?php
    if(isset($_POST[\'submitStu\'])){
        $stuNum=$_POST[\'stuNum\'];
        if($stuNum>=0){
            echo \'<div>\';
            echo \'<form action="" method="post" name="form1">\';
                echo \'<table border="1" >\';
                    echo \'<tr><td>Sno:</td><td>Name:</td><td>Score:</td></tr>\';
                    for($i=0;$i<$stuNum;$i++){
                        echo \'<tr><td><input type="text" name="XH[]"/></td><td><input type="text" name="XM[]"/></td><td><input type="text" name="CJ[]"/></td></tr>\';
                    }
                    echo \'<tr><td colspan="3"><input type="submit" value="OK" name="bt_stu"/></td></tr>\';
                echo \'</table>\';
            echo \'</form>\';
            echo \'</div>\';
        }else{
            echo "Please input corrent num";
        }
    }
?>

<?php

    if(isset($_POST[\'bt_stu\'])){
        $XH=$_POST[\'XH\'];
        $XM=$_POST[\'XM\'];
        $CJ=$_POST[\'CJ\'];
        array_multisort($CJ,$XH,$XM);
        $sum[]=null;
        for($i=0;$i<count($XH);$i++){
            $sum[$i]=array($XH[$i],$XM[$i],$CJ[$i]);   //里面每一个元素都是一个数组
        }
        echo \'<div>The score has been sort:</div><br>\';
        echo \'<div>\';
            echo \'<table border="1">\';
                echo \'<tr><td>Sno:</td><td>Name:</td><td>Score:</td></tr>\';
                    for($i=0;$i<count($sum);$i++){
                        echo "<tr><td>{$sum[$i][0]}</td><td>{$sum[$i][1]}</td><td>{$sum[$i][2]}</td></tr>";
                    }
                    /*foreach($sum as $value){
                        list($stu_num,$stu_name,$stu_score)=$value;
                        echo "<tr><td>$stu_num</td><td>$stu_name</td><td>$stu_score</td></tr>";
                    }*/
            echo \'</table>\';
        echo \'</div>\';
    }

?>