其他分享
首页 > 其他分享> > 1.获取学生案例

1.获取学生案例

作者:互联网

1.案例准备

2.思路

注意:在form标签有两个属性,action用来提交后端页面,method规定get/post方法
<form action="getscore.php" method="get"></form>

3.代码

(1)getscore.html

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>获取学生成绩</title>
		<style type="text/css">
			*{
				margin: 0px;
				padding: 0px;
				list-style: none;
				text-decoration: none;
			}
				
			form{
				text-align: center;
			}
			span{
				font-weight: bold;
				font-size: 20px;
			}
			input[type="submit"]{
				width:40px;
				height:20px;
				border: none;
				cursor: pointer;
				margin-top: 20px;
				text-align: center;
				/* display: block; */
			}
		</style>
	</head>
	<body>
		<form action="getscore.php" method="get">
		<span>
			学号:
		</span>
		<input type="text" name="idname" id="idname" value="" /><br>
			<input type="submit" name="" id="" value="查找" />
		</form>
	</body>
</html>

(2)getscore.php

<!DOCTYPE html>
<html>
	<head>
		<title></title>
		<style>
			*{
				margin: 0px;
				padding: 0px;
			}
		</style>
	</head>
	<body>
		<?php
			// 二维数组模拟数据库
			$data=array();
			$data["123"]=array("name"=>"张三","chinese"=>"80","math"=>"60","english"=>"96");
			$data["456"]=array("name"=>"李四","chinese"=>"78","math"=>"90","english"=>"67");
			$data["789"]=array("name"=>"王五","chinese"=>"90","math"=>"97","english"=>"76");
			// get方法得到表单html提交内容
			$idname=$_GET["idname"];
			// 传递结果
			$result=$data[$idname];
		?>
		<?php
			if(array_key_exists($idname,$data)){
		?>
		<h1><?php echo $result["name"] ?>成绩表</h1>
		<ul>
			<li>语文:<?php echo $result["chinese"] ?></li>
			<li>数学:<?php echo $result["math"] ?></li>
			<li>英语:<?php echo $result["english"] ?></li>
		</ul>
		<?php }else{ ?>
		<div>
			<p>
				查询不到该学生!
			</p>
		</div>
		<?php } ?>
	</body>
<html>

标签:chinese,获取,text,getscore,表单,学生,案例,html,0px
来源: https://www.cnblogs.com/mywifeisMsHu/p/15325360.html