TP中分页函数默认会将GET链接转化,所以有一些汉字在传值时会出错,特此写出以下函数,不改变链接模式,追加跳转参数的方式/*<br>
* 数据分页<br>
* 参数 $count数据条数 $row 调用条数<br>
* 返回值<br>
* $array[limit] sql坐标<br>
* $array['pages'] 分页链接坐标<br>
*/<br>
function page($count,$row){<br>
if(!$count){return '';}//空数据将跳出<br>
$url = $_SERVER["REQUEST_URI"]; //读取链接<br>
$page = $_GET['page']?$_GET['page']:1; //读取分页坐标<br>
$acount = $count; //数据条数<br>
$pcount = ceil($acount/$row); //分页数<br>
$url = $_GET['page']?str_replace(array('/page/'.$_GET['page'],'&page='.$_GET['page']),'',$url):$url; //去除page参数<br>
$limit = ($page-1)*$row.','.$row; //limit调用<br>
$pagetpl= '<div>[info]</div> <ul> [first] [link] [end] </ul>'; //链接坐标模板<br>
<br>
//链接模板<br>
if(strstr($url,'&')||strstr($url,'=')){<br>
$url = $url.'&page=[url]';<br>
}elseif(substr($url,-5)=='.html'){<br>
$url = substr($url,0,-5).'/page/[url].html';<br>
}else{<br>
$url = $url.'/page/[url]';<br>
}<br>
<br>
//信息简介<br>
$info = '共 '.$acount.' 条信息 '.$page.'/'.$pcount.' 页';<br>
<br>
//第一页<br>
$first = ($page!=1)?'<li><a>第一页</a></li>':'';<br>
<br>
//最后一页<br>
$end = ($page!=$pcount)?'<li><a>最后一页</a></li>':'';<br>
<br>
//上一页<br>
$prev = ($page-1)
$prev = $prev?'<li><a>上一页</a></li>':$prev;<br>
<br>
//下一页<br>
$next = ($page+1)>$pcount?'':$page+1;<br>
$next = $next?'<li><a>下一页</a></li>':$next;<br>
<br>
//链接坐标<br>
$pagelist = '';<br>
for($i =1;$i
if($i == $page){<br>
$pagelist .= "<li><a>$i</a></li>";<br>
}else{<br>
$pagelist .= "<li><a>$i</a></li>";<br>
}<br>
}<br>
$pagelist = $prev.$pagelist.$next;<br>
$pagelist = ($pcount>1)?$pagelist:'';<br>
$show = str_replace('[info]',$info,$pagetpl);<br>
$show = str_replace('[first]',$first,$show);<br>
$show = str_replace('[link]',$pagelist,$show);<br>
$show = str_replace('[end]',$end,$show);<br>
<br>
$r['pages'] = $show;<br>
$r['limit'] = $limit;<br>
return $r;<br>
}
调用方法 TP框架$M = M('article');<br>
$page = page($M->where($w)->count(),25);<br>
$list = $M->where($w)->order('wd_px desc,wd_id desc')->limit($page['limit'])->select();<br>
$this->assign('page',$page['pages']);<br>
$this->assign('list',$list);
该方法不局限于TP内,适用于所有PHP程序
原帖地址http://www.90coder.com/Home/Index/article/tid/46.html
AD:真正免费,域名+虚机+企业邮箱=0元