Home > Backend Development > PHP Tutorial > PHP实现对mysql数据库内容分页显示

PHP实现对mysql数据库内容分页显示

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-23 13:49:53
Original
1126 people have browsed it

<?php $conn=mysql_connect('127.0.0.1','root','');mysql_query('use test',$conn);mysql_query('set names utf8',$conn);$perNumber=3; //每页显示的记录数$page=$_GET['page']; //获得当前的页面值$count=mysql_query("select count(*) from kangbiao"); //获得记录总数$rs=mysql_fetch_array($count); $totalNumber=$rs[0];$totalPage=ceil($totalNumber/$perNumber); //计算出总页数if (!isset($page)) { $page=1;} //如果没有值,则赋值1$startCount=($page-1)*$perNumber; //分页开始,根据此方法计算出开始的记录$result=mysql_query("select * from kangbiao limit $startCount,$perNumber"); //根据前面的计算出开始的记录和记录数echo "<table border='1'>";echo "<tr>";echo "<th>id</th>";echo "<th>name</th>";echo "<th>age</th>";echo "<th>grade";echo "</th>
</tr>";while ($row=mysql_fetch_array($result)) {echo "<tr>"; echo "<td>$row[0]</td>";  echo "<td>$row[1]</td>"; echo "<td>$row[2]</td>"; echo "<td>$row[3]</td>";  //显示数据库的内容echo "</tr>";}echo "";if ($page != 1) { //页数不等于1?><a href="02.php?page=<?php%20echo%20%24page%20-%201;?>">上一页</a> <!--显示上一页--><?php }for ($i=1;$i<=$totalPage;$i++) {  //循环显示出页面?><a href="02.php?page=<?php%20echo%20%24i;?>"><?php echo $i ;?></a><?php }if ($page<$totalPage) { //如果page小于总页数,显示下一页链接?><a href="02.php?page=<?php%20echo%20%24page%20+%201;?>">下一页</a><?php } ?>
Copy after login

运行结果:



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template