<?phpheader("content-type:text/html;charset=utf-8"); //头部编码mysql_connect("localhost","root",""); //连接数据库服务器mysql_select_db("db_stu"); //选择数据库mysql_query("set names utf8"); //数据库的编码格式$select = mysql_query("select distinct km from tb_grade;"); //mysql语句,在tb_grade表中查找km 并且去掉重复项(distinct)?> 姓名 学号:
科目: ".$row['km']."
<?php@$ckm = $_POST['km']; //把科目的 表单赋值给$ckm@$fs = $_POST['fs']; //把选择学号姓名的表单赋值给$fsif ($fs != null ) { //判断是否等于空值if ($fs == '学号') { //如果表单等于学号,则执行下面语句@$cxh = $_POST['b']; //$cj = mysql_query("select cj from tb_grade where xh={$cxh} and km='{$ckm}';"); //数据库选择成绩输出 返回一个资源给客户端@$fanhui = mysql_num_rows($cj); //计算返回的资源的行数if ($fanhui != 0) { //判断返回的资源是否等于0while ($row = mysql_fetch_array($cj)) { //while 循环echo "学号为".$cxh."的同学".$ckm."的成绩为".$row[0]; //输出}}else{echo "学号为".$cxh."找不到";}}elseif ($fs = '姓名') {@$cxm = $_POST['b'];$cj2 = mysql_query("select cj from tb_grade,tb_stuinf where tb_grade.xh=tb_stuinf.xh and xm='{$cxm}' and km='{$ckm}';"); //多表关联@$fanhui = mysql_num_rows($cj2);if($fanhui != 0){while ($row = mysql_fetch_array($cj2)) {echo @$cxm.'的'.$ckm.'成绩为:'.$row[0];}}else{echo @$cxm.'的'.$ckm.'成绩查不到';}}}?>
转载于:https://www.cnblogs.com/sujc-blogs/p/9722528.html