实现翻页跳转功能
<?php $limit = 25; if (!empty($start)) $start = 0; if (!empty($s)) $s = 0; mysql_connect("localhost", "", ""); mysql_select_db(database); //统计数据库记录总数 $result = mysql_query("select * from table"); $num = mysql_numrows($result); $result = mysql_query("select * from table order by id limit $start,$limit"); $numb = mysql_numrows($result); echo "<table>"; if (!empty($numb)) { for ($i = 0; $i < $numb; $i++) { $val = mysql_result($result, $i, "val"); $val1 = mysql_result($result, $i, "val1"); echo "<tr><td>$val</td><td>$val1</td></tr>"; } } echo "</table>"; //数字循环翻页的控制 echo "<table>"; echo "<tr><td>页:</td>"; //前翻控制 if ($s > 20) { if ($s == 21) { $st = $s - 21; } else { $st = $s - 20; } $pstart = $st * $limit; echo "<td><a href=page.php?"; echo "start=$pstart&s=$st>prve</a></td>"; } echo "<td> >></td>"; //设置当前页对应页数无链接功能 $star = $start; //注意循环的初始附值,仔细想想为什么不是 0 for ($page = $s; $page < ($num / $limit); $page++) { $start = $page * $limit; echo "<td>"; if ($page != $star / $limit) { echo "<a href=page.php?"; echo "start=$start&s=$s>"; } echo $page; if ($page != $star / $limit) { echo "</a>"; } echo "</td>"; //控制数字页面限制显示功能,控制只显示 20 页 if ($page > 0 && ($page % 20) == 0) { if ($s == 0) { $s = $s + 21; } else { $s = $s + 20; } $start = $start + $limit; if ((($num / $limit) - 1) > $page) { echo "<td> <<</td><td><a href'page.php?"; echo "start=$start&s=$s>next</a></td>"; } //注意跳出循环的控制 break; } } echo "</tr></table>"; ?>
以上的程已序可以完成强大的循环翻页功能
本文链接:http://www.phprm.com/develop/60ea3c390e808057e5215d6f52357b40.html
收藏随意^^请保留教程地址.