PHP+MYSQL+HTML 学生成绩查询

首先创建一个数据库名为 xscj,表信息如下:

页面信息为:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>学生成绩查询</title>
<style type="text/css">
#apDiv1 {
 position:absolute;
 width:200px;
 height:151px;
 z-index:1;
 left: 199px;
 top: 11px;
}
#apDiv2 {
 position:absolute;
 width:319px;
 height:57px;
 z-index:2;
 left: 506px;
 top: 57px;
 font-size:50px;
 color:#BBB;
}
#apDiv3 {
 position:absolute;
 width:1147px;
 height:65px;
 z-index:3;
 left: 36px;
 top: 175px;
}
#a4
{
 position:absolute;
 left: 264px;
 top: 213px;
 width: 760px;
 height: 321px;
}
</style>
</head>

<body>
<div id="apDiv1"><img src="img/res07_attpic_brief.jpg" width="383" height="157" /></div>
<div id="apDiv2">成绩查询结果</div>
<div id="apDiv3"><hr></div>
<div id="a4">
<?php
$link=mysql_connect('localhost','root','123') or die ("不能连接数据库,错误原因:".mysql_error());

mysql_select_db('xscj',$link) or die ("不能选择数据库");

$xuehao=$_POST["学号"];
$name=$_POST["姓名"];
$project=$_POST["专业"];
if(!$xuehao)
{echo "<script type='text/javascript'> alert('请输入学号');location.href='mm.php';</script>";}
else{
$q="select * from xs where 学号='$xuehao'";
if($name)

{$q.="and 姓名='$name'";}
if($project)

{$q.="and 专业名='$project'";}
$result=mysql_query($q);
}
if(@mysql_num_rows($result)==0)
 
 {echo "<script type='text/javascript'> alert('无此人记录');location.href='mm.php';</script>";}
else
{

 echo "<br>";
 while ($row=mysql_fetch_array($result))
 {

  //显示所查询学生的信息表
 
  echo "<table with=600 border='0' align='center' bordercolor='#000000'>";
  echo "<tr><td width=70 height=30 bgcolor=#cccccc>学号</td>";
  echo "<td width=100 height=30>$row[学号]</td>";
  echo "<td width=70 height=30 bgcolor=#cccccc>姓名</td>";
  echo "<td width=70 height=30>$row[姓名]</td></tr>";
 
  echo "<tr><td width=70 height=30 bgcolor=#cccccc>专业名</td>";
  echo "<td width=100 height=30>$row[专业名]</td>";
  echo "<td width=70 height=30 bgcolor=#cccccc>出生日期</td>";
     echo "<td width=100 height=30>$row[出生日期]</td></tr>";
 
  echo "<tr><td width=70 height=30 bgcolor=#cccccc>总学分</td>";
     echo "<td width=100 height=30>$row[总学分]</td></tr>";
 }
 echo '</table>';
 echo "<br>";
 echo "<br>";echo "<br>";
echo "<div align=center><font color='黑色'><h2>课程信息如下:</h2></font></div>";
echo "<br>";

echo "<br>"; 
//显示学生所选课程的成绩情况
echo "<table width=600 border='1' align='center' bordercolor='#000000'>";
echo "<tr><td width=35height=30 bgcolor=#cccccc>学号</td>";
echo "<td width=35 height=30 bgcolor=#cccccc>成绩</td>";
echo "<td width=50 height=30 bgcolor=#cccccc>课程名</td>";
echo "<td width=50 height=30 bgcolor=#cccccc>课程号</td>";
echo "<td width=35 height=30 bgcolor=#cccccc>学分</td>";
echo "<td width=35 height=30 bgcolor=#cccccc>学时</td></tr>";
$sql="select  * from  xs_kc_st where 学号='$xuehao'"; //在视图xs_kc_st 中查询
$res=mysql_query($sql);
while($rw=mysql_fetch_row($res))
  
 { echo '<tr>';
 foreach($rw as $data)
{echo '<td>'.$data.'</td>';} 
echo '<tr>';}
 echo '</table>';
 mysql_free_result($result);

}
?>

</div>
</body>
</html>

 

页面2:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>学生成绩查询</title>
<style type="text/css">


#apDiv1 {
 position:absolute;
 width:658px;
 height:308px;
 z-index:5;
 left: 371px;
 top: 196px;
}

#apDiv2 {
 position:absolute;
 width:412px;
 height:91px;
 z-index:6;
 left: 504px;
 top: 62px;
 font-size:50px;
 color:#FFF;
}
#bj
{
 position:absolute;
 z-index:1;
 width:1345px;
 height:308px;
 left: 2px;
 top: -1px;
}
</style>
</head>

<body>


<div id="bj">

<div id="apDiv1">

<form action="mm2.php" method="post">

<table width="586" border="1" align="center" bordercolor="#000000">
  <tr>
    <td height="59" colspan="2"><center><h2>
      请输入查询条件
    </h2></center></td>
  </tr>
  <tr>
    <td width="51" height="51"><h3>学号:</h3></td>
    <td width="168"><select name="学号">
 <?php
$link = mysql_connect("localhost", "root", "123")

        or die("Could not connect : " . mysql_error());

mysql_select_db("xscj") or die("Could not select database");
$query = mysql_query("SELECT * FROM xs") ;
while($row = mysql_fetch_array($query)) {
        $id = $row['学号'];

        echo "<option value='$id'>$id</option>";
}
$stunumber=$_GET["q1"];
$sql="select 姓名,专业名,课程名,成绩,学分 from v_s where 学号='$stunumber'";

$result=mysql_query($sql);
$row=mysql_fetch_array($result);
?>
  </select></td>
  </tr>
  <tr>
    <td height="51"><h3>姓名:</h3></td>
    <td><input type="text" name="姓名" /></td>
  </tr>
  <tr>
    <td height="51"><h3>专业:</h3></td>
    <td width="20" height="36">
    <select name="专业">
    <option>所有专业</option>
    <option>计算机</option>
    <option>通信工程</option>
    </select>
  </tr>
  <tr>
    <td height="65" colspan="2"><center>
      <input type="submit" value="查询" />
      &nbsp;&nbsp;&nbsp;&nbsp;
      <input type="reset" value="取消" />
    </center></td>
  </tr>
</table>
</form>
</div>
<div id="apDiv2"><strong>学生成绩查询系统</strong></div>
<img src="img/2.jpg" width="1394" height="650" /> </div>
</body>
</html>

 

网页预览如下:

下拉菜单中可以获取出数据库的学号,点击学号 选择专业后会查询出相应的内容

 

 

 

 

 

如果没有该学生信息则会提示无此人记录

 

  • 14
    点赞
  • 115
    收藏
    觉得还不错? 一键收藏
  • 8
    评论
学生成绩管理系统是一种用于记录和管理学生学习成绩的软件系统。它通常由前端界面和后端数据库组成。其中,前端使用HTML、CSS和JavaScript来实现用户界面,后端使用PHPMySQL来处理数据和存储信息。 在学生成绩管理系统中,PHP用于处理用户输入的请求并与数据库进行交互。通过使用PHP的数据库连接函数,可以连接到MySQL数据库,并执行相关的查询和操作。 例如,可以使用PHP编写代码来实现以下功能: 1. 学生信息管理:可以编写代码来添加、删除和修改学生的基本信息,如学号、姓名、班级等。 2. 成绩录入:可以输入学生的各科成绩,并将其存储到数据库中,以便后续查询和统计。 3. 成绩查询:可以通过学号或姓名来查询学生成绩,并将查询结果显示在前端界面中。 4. 成绩统计:可以统计每个学科的平均成绩、最高成绩和最低成绩,并将结果显示给用户。 为实现以上功能,可以使用PHP中提供的MySQL相关函数,如mysqli_connect()连接数据库、mysqli_query()执行查询语句、mysqli_fetch_array()获取查询结果等。 在编写PHP代码时,需要注意安全性和效率。可通过使用预处理语句和参数化查询来防止SQL注入攻击,并使用适当的索引和优化技术来提高系统性能。 综上所述,学生成绩管理系统的php mysql代码主要涉及与数据库的连接、学生信息管理、成绩录入、成绩查询成绩统计等功能,通过合理使用PHPMySQL函数可以实现。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值