PHP+MYSQL+HTML 学生成绩查询

首先建立一个数据库名为 xscj,表信息以下:javascript

页面信息为:php

<!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>css

<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());html

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

$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)mysql

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

{$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))
 {post

  //显示所查询学生的信息表
 
  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>";fetch

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>

 

网页预览以下:

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

 

 

 

 

 

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