Blogger Information
Blog 34
fans 2
comment 2
visits 22730
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
分页-20180501-16:32
AsNwds_MIS王的博客
Original
636 people have browsed it

实例

<!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>

运行实例 »

点击 "运行实例" 按钮查看在线实例

无标题.png

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post