PHP开发之留言板展示页面
本留言板功能共有三个页面,留言展示页,留言编辑页,留言回复页。本节介绍的就是展示页面。
<?php
session_start();
header("content-type:text/html;charset=utf-8");
//连接数据库
$link = mysqli_connect("localhost","root","root","message");
mysqli_set_charset($link,"utf8");
if (!$link) {
die("连接失败: " . mysqli_connect_error());
}
//连接数据库
$SQL = "SELECT * FEOM DETAILS";//设置查询指令
$result=mysqli_query($link,$sql);//执行查询
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="format-detection" content="telephone=no" />
<title>留言板</title>
<style>
.top{
width:410px
}
.fl{
float:left
}
.klytd {width:100px;
text-align:left
}
</style>
</head>
<body>
<div style="margin:0px auto;">
<!--头部图片-->
<div>
<img style="width:400px" src="https://img.php.cn/upload/course/000/000/007/5816db62346b9319.jpg">
</div>
<!--中间内容-->
<div>
<div style="width:400px;" class="fl font">
<div style="margin:0px auto;"><h2>留言列表</h2>
<form method="post" action="list.php">
<?php while($row=mysqli_fetch_assoc($result)):?>
<table>
<tr><td>留言时间:</td><td><?php echo $row['time'];?></td></tr>
<p><button type="button" value="回复">
<a href="reply_list.php?id=<?php echo $row['id'];?>">回复</a></button></p>
<tr><td>留言人:</td><td><?php echo $row['name'];?></td></tr>
<tr><td>标题:</td><td><?php echo $row['title'];?></td></tr>
<tr><td>内容:</td><td><?php echo $row['content'];?></td></tr>
<tr><td>回复:</td><td><?php echo $row['reply'];?></td></tr>
</table>
</form>
<br/>
<hr>
<?php endwhile;?>
</div>
<div>
<button type="button" value="发表留言"><a href="form.html">发表留言</a></button>
</div>
</div>
</div>
</body>
</html>PHP代码是可以和HTML写在同一个页面的。
PHP代码是先连接数据库,然后执行SQL查询语句,将查询到的数据显示在列表页面上。
HTML页面中,我们只需要写一个循环,就可以将查询到的所有数据都循环出来。
