php 输出 table
<body>
<?php
sleep(3);//执行到这里的时候等待3秒
/*这里的数据是假数据,真正的场景中数据基本上都是来自数据库。*/
$arr = array();
$arr[0] = array('name'=>'三国演义','auhor'=>'罗贯中','category'=>'古典文学','desc'=>'一个群雄争霸的年代');
$arr[1] = array('name'=>'水浒传','auhor'=>'施耐庵','category'=>'历史文学','desc'=>'108好汉的故事');
$arr[2] = array('name'=>'红楼梦','auhor'=>'曹雪芹','category'=>'爱情文学','desc'=>'一个封建王朝的繁荣末落');
$arr[3] = array('name'=>'西游记','auhor'=>'吴承恩','category'=>'神话文学','desc'=>'佛教与道教之间的较量');
$arr[4] = array('name'=>'西厢记','auhor'=>'王实甫','category'=>'古典文学','desc'=>'封建王朝悲催的爱情故事');
?>
<table cellpadding="0" cellspacing="0">
<thead>
<tr>
<td>名称</td>
<td>作者</td>
<td>分类</td>
<td>描述</td>
</tr>
</thead>
<tbody>
<?php foreach($arr as $value) { ?>
<tr>
<td><?php echo $value['name']; ?> </td>
<td><?php echo $value['auhor']; ?> </td>
<td><?php echo $value['category']; ?> </td>
<td><?php echo $value['desc']; ?> </td>
</tr>
<?php } ?>
</tbody>
</table>
</body>
设置请求头 解决乱码
header('Content-Type:text/html; charset=utf-8');
echo '<div style="color:red;"><span>测试数据</span><span>测试数据</span><span>测试数据</span></div>';
foreach 相当于 for
<div>
<?php
$arr = array();
$arr['123'] = array("username"=>"张三","chinese"=>"130","math"=>"149","english"=>"146","summary"=>"298");
$arr['124'] = array("username"=>"李四","chinese"=>"100","math"=>"140","english"=>"136","summary"=>"298");
$arr['125'] = array("username"=>"王五","chinese"=>"90","math"=>"139","english"=>"126","summary"=>"298");
$arr['126'] = array("username"=>"赵六","chinese"=>"30","math"=>"50","english"=>"80","summary"=>"100");
$code = $_POST['code'];
if($code == 'admin'){
foreach($arr as $value){
echo "<ul><li>姓名:$value[username]</li><li>语文:$value[chinese]</li><li>数学:$value[math]</li><li>英语:$value[english]</li><li>综合:$value[summary]</li></ul>";
}
}else{
$score = $arr[$code];
echo "<ul><li>姓名:$score[username]</li><li>语文:$score[chinese]</li><li>数学:$score[math]</li><li>英语:$score[english]</li><li>综合:$score[summary]</li></ul>";
}
?>
</div>
<form action="03考生成绩.php" method="post">
考号:<input type="text" name="code"><input type="submit" value="查询">
</form>
iframe调用php
<?php
$uname = $_POST['username'];
$pw = $_POST['password'];
if($uname == 'admin' && $pw == '123'){
?>
<script type="text/javascript">
parent.document.getElementById('info').innerHTML = '登录成功';
</script>
<?php }else{
?>
<script type="text/javascript">
parent.document.getElementById('info').innerHTML = '登录失败';
</script>
<?php } ?>
- 隐藏帧实现局部更新 实际上iframe就相当于页面的子页面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>登录</title>
<script type="text/javascript">
</script>
</head>
<body>
<div>
<form action="./iframe.php" method="post" target="myframe">
用户名:<input type="text" name="username"><span id="info"></span><br>
密码:<input type="text" name="password">
<input type="submit" value="登录">
</form>
</div>
<iframe width="0" height="0" frameborder="0" name=