批改状态:合格
老师批语:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>商品信息查询</title>
<style>
table,th,td {
border: 1px solid grey;
height: 25px;
}
table th {
background-color: lightgrey;
}
table {
border-collapse: collapse;
width: 70%;
margin: 30px auto;
text-align: center;
}
h4 {
text-align: center;
}
h4 a {
text-decoration: none;
display: inline-block;
border: 1px solid #dfeffc;
min-width:35px;
height:25px;
padding-top:5px;
margin: 2px;
color: #00b0f0;
}
h4 a:hover{
background-color: #E2F1FD;
}
</style>
</head>
<body>
<?php
$db =mysqli_connect('localhost','root','root');
mysqli_select_db($db,'php');
$num =4;
$page =isset($_GET['p']) ? $_GET['p'] : 1;
$offset =($page-1)*$num;
$sql ="select * from goods LIMIT {$offset},{$num};";
$res =mysqli_query($db,$sql);
$rows =mysqli_fetch_all($res,MYSQLI_ASSOC);
$number =mysqli_query($db,"select count(*) from goods");
list($total) =mysqli_fetch_row($number);
$pages = ceil($total /$num);
?>
<table>
<caption><h2>商品信息表</h2></caption>
<tr>
<th>商品编号</th>
<th>商品名称</th>
<th>商品种类</th>
<th>商品数量</th>
<th>商品价格</th>
</tr>
<?php foreach($rows as $row): ?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['category']; ?></td>
<td><?php echo $row['amount']; ?></td>
<td><?php echo $row['Price']; ?></td>
</tr>
<?php endforeach; ?>
</table>
<h4>
<a href="http://www.a.com/0428/0428.php?p=1">首页</a>
<a href="http://www.a.com/0428/0428.php?p=<?php echo (($page-1)==0) ? 1 :($page-1); ?>">前页</a>
<?php for($i=1;$i<=$pages;$i++): ?>
<a href="http://www.a.com/0428/0428.php?p=<?php echo $i ?>"><?php echo $i ?></a>
<?php endfor; ?>
<a href="http://www.a.com/0428/0428.php?p=<?php echo (($page+1)>$pages) ? $pages : ($page+1); ?>">后页</a>
<a href="http://www.a.com/0428/0428.php?p=<?php echo $pages; ?>">尾页</a>
</h4>
</body>
</html>点击 "运行实例" 按钮查看在线实例

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号