标签:host code lin fat 注册时间 count ext foreach str
<?php $pdo = new PDO(‘mysql:host=127.0.0.1;dbname=1703plus‘,‘root‘,‘root‘); //接收当前页 $page = empty($_GET[‘page‘]) ? 1 : $_GET[‘page‘]; //查询总条数 $count_sql = "select count(username) from users"; $res = $pdo->query($count_sql)->fetch(PDO::FETCH_ASSOC); $count = $res[‘count(username)‘]; //每页显示的条数 $length = 20; //总页数 $num_page = ceil($count/$length); //偏移量 $limit = ($page-1)*$length; //查询 $sql = "select * from users limit $limit,$length"; $data = $pdo->query($sql)->fetchAll(PDO::FETCH_ASSOC); ?> <link rel="stylesheet" type="text/css" href="bootstrap4.min.css"> <table class=‘table‘> <tr> <th>主键</th> <th>账号</th> <th>昵称</th> <th>个性签名</th> <th>注册时间</th> <th>操作</th> </tr> <?php foreach($data as $k => $v){ ?> <tr> <td><?php echo $v[‘user_id‘];?></td> <td><?php echo $v[‘username‘];?></td> <td><?php echo $v[‘kinfname‘];?></td> <td><?php echo $v[‘fationname‘];?></td> <td><?php echo date(‘Y-m-d H:i:s‘,$v[‘usertime‘]);?></td> <td> <a href="">删除</a> <a href="">修改</a> </td> </tr> <?php } ?> </table> <a class="page-link" href="baodufenye.php?page=1">首页</a> <?php //判断页数前面是否还有5页 if($page>=5){ for($i=$page-4;$i<$page;$i++){ echo "<a href=‘baodufenye.php?page=".$i." ‘>$i </a>" ; } }else{ for($i=1;$i<$page;$i++){ echo ‘<a href=baodufenye.php?page=".$i.">‘.$i.‘ </a>‘; } } ?> <a href="baodufenye.php?page=<?php echo $page;?>"><?php echo $page ?></a> <?php for($i=$page+1;$i<=$page+4;$i++){ echo "<a href=‘baodufenye.php?page=".$i." ‘>$i</a> " ; } ?> <a href="list.php?page=<?php echo $num_page;?>">尾页</a>
标签:host code lin fat 注册时间 count ext foreach str
原文地址:https://www.cnblogs.com/npb1026/p/11128434.html