$qh =mysql_query( "select count(*) as rcnt from table where your_condition_here order by whatever" ); $data =mysql_fetch_array( $qh ); $nr = $data [ "rcnt" ]; //判断偏移量参数是否传递给了脚本,如果没有就使用默认值0 if ( empty empty ( $offset )) { $offset =0; } //查询结果(这里是每页20条,但你自己完全可以改变它) $result =mysql_query( "select id,name,phone from table where your_condition_here order by whatever limit $offset, 20" ); //显示返回的20条记录 while ( $data =mysql_fetch_array( $result )) { //换成你用于显示返回记录的代码 } //下一步,要写出到其它页面的链接 if (! $offset ) //如果偏移量是0,不显示前一页的链接 { $preoffset = $offset -20; print "<a href=" $php_self ?offset= $preoffset ">前一页</a> " ; } //计算总共需要的页数 $pages = ceil ( $nr /20); //$pages变量现在包含所需的页数 for ( $i =1; $i <= $pages ; $i ++) { $newoffset =20* $i ; print "<a href=" $php_self ?offset= $newoffset ">$i</a> " ; } //检查是否是最后一页 if ( $pages !=0 && ( $newoffset /20)!= $pages ) { //开源代码phpfensi.com print "<a href=" $php_self ?offset= $newoffset ">下一页</a> " ; }
查看更多关于简单实用php mysql分页代码的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did27971