求一段php分页代码,就像网上用于图书的分页,请教各位高手

来源:百度知道 编辑:UC知道 时间:2024/05/25 04:16:32
希望能达到像如下网址这样的分页效果:http://www.tuku.cc/list/comic_1_1.htm

<?php
//通用的分页,输出样式根据自己喜欢样式更改就可以了
/*
* Created on 2006-11-16
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/

//为了避免重复包含文件而造成错误,加了判断函数是否存在的条件:
if(!function_exists(page))
{
function page($sql,$url=''){
//定义几个全局变量:
//$page:当前页码;
//$begincount:查询的起始项,limit的第一个参数;
//$pagenav:分页条
global $page,$begincount,$pagenav,$rows;

//$totle:信息总数;
//$rows:每页显示信息数,这里设置为默认是5;
//$url:分页导航中的链接,除了加入不同的查询信息“page”外的部分都与这个URL相同。

$rows = 1;
//$pagenum = $displaypg;

$result = mysql_query($sql) or die("Could not query:" . mysql_error());
$total = mysql_num_rows($result);
if(!$page) $page=1;

//在URL后加page查询信息
$url.="&page";

$lastpg=ceil($total/$rows); //最后页,也是总页数
//$page=min($lastpg,$page);