实现“上一页”和“下一页按钮

?php//本例子摘自phpbuilder.com//稍加翻译//sprming@netease.com$limit=20;
// 每页显示的行数$numresults=mysql_query(select *澳门新浦京娱乐游戏, from TABLE where
YOUR CONDITIONAL HERE order by
WHATEVER);//换成你所需要的sql语句$numrows=mysql_num_rows($numresults);//
next determine if offset has been passed to script, if not use 0if
(empty($offset)) {$offset=1;}// 得到查询结果$result=mysql_query(select
id,name,phone .from TABLE where YOUR CONDITIONAL HERE .order by WHATEVER
limit $offset,$limit);// 现在显示查询结果while
($data=mysql_fetch_array($result)) {//
在这里插入您要显示的结果以及样式}// 显示按钮if ($offset!=1) { // bypass
PREV link if offset is 1$prevoffset=$offset-20;print a
href=/$PHP_SELF?offset=$prevoffset//a /n;}//
计算页面数$pages=intval($numrows/$limit);// $pages now contains int of
pages needed unless there is a remainder from divisionif
($numrows%$limit) {// has remainder so add one page$pages++;}for
($i=1;$i=$pages;$i++) { // 显示页数$newoffset=$limit*($i-1);print a
href=/$PHP_SELF?offset=$newoffset/$i/a /n;}// check to see if last
pageif (!(($offset/$limit)==$pages) && $pages!=1) {// not last page so
give NEXT link$newoffset=$offset+$limit;print a
href=/$PHP_SELF?offset=$newoffset//ap/n;}?

You can leave a response, or trackback from your own site.

Leave a Reply

网站地图xml地图