展开全部
index.php?page=1
获得页数$_GET["page"]==""?$page=1:$page=$_GET["page"];// 没有页数就是第一页
数据库$sql="select count(*) *******"
$row=mysql_fetch_array(mysql_query($sql,$link))
$pagenum=ceil($row[0]/10); //每页10条,1.1就是2页
index.php 首页
$page-1是上一页
for($i=1;$i<$pagenum+1;$++) 循环输出 1\2\3\....页
index.php?page=1 =【1】
index.php?page=2 =【2】
$page+1是下一页
index.php?page=$pagenum;//尾页
获得页数$_GET["page"]==""?$page=1:$page=$_GET["page"];// 没有页数就是第一页
数据库$sql="select count(*) *******"
$row=mysql_fetch_array(mysql_query($sql,$link))
$pagenum=ceil($row[0]/10); //每页10条,1.1就是2页
index.php 首页
$page-1是上一页
for($i=1;$i<$pagenum+1;$++) 循环输出 1\2\3\....页
index.php?page=1 =【1】
index.php?page=2 =【2】
$page+1是下一页
index.php?page=$pagenum;//尾页
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我一个函数分页函数,下面有使用例子
<?
/*
'PID 页面中的其它传参连接
'page 要显示的页码
'Vcount 总记录数
'Pnum 每页记录数
'className 超连接样式
*/
function ThePage($Pid,$page=1,$Vcount,$Pnum,$className){
$Pcount = ceil($Vcount/$Pnum);
if($page>$Pcount) $page=$Pcount;
$StartPageNum=1;
while($StartPageNum+10<=$page){
$StartPageNum=$StartPageNum+10;
}
$EndPageNum=$StartPageNum+9 ;
if($EndPageNum>$Pcount) $EndPageNum=$Pcount;
$show = $show."<tr><td colspan='10' bgcolor='' align='right' style='padding-right:25px;padding-top:5px;' class='".$className."'>";
$show = $show."共<b>".$Pcount."</b>页 共有<b>".$Vcount."</b>记录 第<b>".$page."</b>页 跳到第 [ ";
if($StartPageNum>1) $show = $show."<a class='".$className."' href='?".$Pid."page=".($StartPageNum-1)."' title='前十页'><font face='webdings'>7</font></a>";
for($go=$StartPageNum;$go<=$EndPageNum;$go++){
if($go!=$page){
$show = $show."<a class='".$className."' href='?".$Pid."page=".$go."'>".$go."</a>";
}else{
$show = $show."<b>".$go."</b>";
}
$show = $show." ";
}
if($EndPageNum<$Pcount) $show = $show."<a class='".$className."' href='?".$Pid."page=".($EndPageNum+1)."' title='下十页'><font face='webdings'>8</font></a>";
$show = $show."] 页";
if($page!=1) $show = $show."<a class='".$className."' href='?".$Pid."page=1'> 首页</a> <a class='".$className."' href='?".$Pid."page=".($page-1)."'>上一页</a>";
if($Pcount-$page!=0) $show = $show. "<a class='".$className."' href='?".$Pid."page=".($page+1)."'> 下一页</a> <a class='".$className."' href='?".$Pid."page=".$Pcount."'>尾页</a>";
$show=$show."</tr></td>";
return $show;
}
//设置参数
$page = $_REQUEST["page"];
if($page=="") $page = 1;
$T = $_GET["T"];
if($T=="") $T = 1;
$Pid = "T=".$T."&";
$wheresql = "where T = ".$T;
$recordListTable = "zc_news";
$Pnum = 10;
$classname = "lwf";
//以下不用修改
$rs = mysql_query("select count(*) from `".$recordListTable."` $wheresql ");
$Vcount = @mysql_result($rs,0);
@mysql_free_result($rs);
$start = ($page - 1) * $Pnum;
$lastNum = $Vcount - ($page - 1) * $Pnum;
$limit = $lastNum > $Pnum ? $Pnum : $lastNum;
$rs = mysql_query("select * from `".$recordListTable."` $wheresql order by orderid desc,ID desc LIMIT $start,$limit");
while($ary = mysql_fetch_array($rs)){
?>
<tr>
<td>
<?=$ary["title"]?>
</td>
</tr>
<?
}
@mysql_free_result($rs);
echo ThePage($Pid,$page,$Vcount,$Pnum,$classname);
?>
<?
/*
'PID 页面中的其它传参连接
'page 要显示的页码
'Vcount 总记录数
'Pnum 每页记录数
'className 超连接样式
*/
function ThePage($Pid,$page=1,$Vcount,$Pnum,$className){
$Pcount = ceil($Vcount/$Pnum);
if($page>$Pcount) $page=$Pcount;
$StartPageNum=1;
while($StartPageNum+10<=$page){
$StartPageNum=$StartPageNum+10;
}
$EndPageNum=$StartPageNum+9 ;
if($EndPageNum>$Pcount) $EndPageNum=$Pcount;
$show = $show."<tr><td colspan='10' bgcolor='' align='right' style='padding-right:25px;padding-top:5px;' class='".$className."'>";
$show = $show."共<b>".$Pcount."</b>页 共有<b>".$Vcount."</b>记录 第<b>".$page."</b>页 跳到第 [ ";
if($StartPageNum>1) $show = $show."<a class='".$className."' href='?".$Pid."page=".($StartPageNum-1)."' title='前十页'><font face='webdings'>7</font></a>";
for($go=$StartPageNum;$go<=$EndPageNum;$go++){
if($go!=$page){
$show = $show."<a class='".$className."' href='?".$Pid."page=".$go."'>".$go."</a>";
}else{
$show = $show."<b>".$go."</b>";
}
$show = $show." ";
}
if($EndPageNum<$Pcount) $show = $show."<a class='".$className."' href='?".$Pid."page=".($EndPageNum+1)."' title='下十页'><font face='webdings'>8</font></a>";
$show = $show."] 页";
if($page!=1) $show = $show."<a class='".$className."' href='?".$Pid."page=1'> 首页</a> <a class='".$className."' href='?".$Pid."page=".($page-1)."'>上一页</a>";
if($Pcount-$page!=0) $show = $show. "<a class='".$className."' href='?".$Pid."page=".($page+1)."'> 下一页</a> <a class='".$className."' href='?".$Pid."page=".$Pcount."'>尾页</a>";
$show=$show."</tr></td>";
return $show;
}
//设置参数
$page = $_REQUEST["page"];
if($page=="") $page = 1;
$T = $_GET["T"];
if($T=="") $T = 1;
$Pid = "T=".$T."&";
$wheresql = "where T = ".$T;
$recordListTable = "zc_news";
$Pnum = 10;
$classname = "lwf";
//以下不用修改
$rs = mysql_query("select count(*) from `".$recordListTable."` $wheresql ");
$Vcount = @mysql_result($rs,0);
@mysql_free_result($rs);
$start = ($page - 1) * $Pnum;
$lastNum = $Vcount - ($page - 1) * $Pnum;
$limit = $lastNum > $Pnum ? $Pnum : $lastNum;
$rs = mysql_query("select * from `".$recordListTable."` $wheresql order by orderid desc,ID desc LIMIT $start,$limit");
while($ary = mysql_fetch_array($rs)){
?>
<tr>
<td>
<?=$ary["title"]?>
</td>
</tr>
<?
}
@mysql_free_result($rs);
echo ThePage($Pid,$page,$Vcount,$Pnum,$classname);
?>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
function my_pager($recordcount,$pagesize,$curr_page,$url){
if(strpos($url,'?')!=false){
$url.="&";
}
else{
$url.="?";
}
$multipage = '';
if($recordcount > $pagesize) {
$page = 10;
$offset = 3;
$pages = ceil($recordcount / $pagesize);
$from = $curr_page - $offset;
$to = $curr_page + $page - $offset - 1;
if($page > $pages) {
$from = 1;
$to = $pages;
}
else {
if($from < 1) {
$to = $curr_page + 1 - $from;
$from = 1;
if(($to - $from) < $page && ($to - $from) < $pages) {
$to = $page;
}
}
elseif($to > $pages) {
$from = $curr_page - $pages + $to;
$to = $pages;
if(($to - $from) < $page && ($to - $from) < $pages) {
$from = $pages - $page + 1;
}
}
}
if($from==2){
$multipage .= "<li><a href=\"".$url."page=1\">1</a></li>";
}
if($from>2){
$multipage .= "<li><a href=\"".$url."page=1\">1</a></li>... ";
}
for($i = $from; $i <= $to; $i++) {
if($i != $curr_page) {
$multipage .= "<li><a href=\"".$url."page=$i\">$i</a></li> ";
}
else {
$multipage .= '<li>'.$i.'</li>';
}
}
if($to<$pages-1){
$multipage.=" ... <li><a href=\"".$url."page=$pages\">$pages</a></li>";
}
if($to==$pages-1){
$multipage.="<li><a href=\"".$url."page=$pages\">$pages</a></li>";
}
}
return $multipage;
}
有点类似于discuz论坛的分页。
if(strpos($url,'?')!=false){
$url.="&";
}
else{
$url.="?";
}
$multipage = '';
if($recordcount > $pagesize) {
$page = 10;
$offset = 3;
$pages = ceil($recordcount / $pagesize);
$from = $curr_page - $offset;
$to = $curr_page + $page - $offset - 1;
if($page > $pages) {
$from = 1;
$to = $pages;
}
else {
if($from < 1) {
$to = $curr_page + 1 - $from;
$from = 1;
if(($to - $from) < $page && ($to - $from) < $pages) {
$to = $page;
}
}
elseif($to > $pages) {
$from = $curr_page - $pages + $to;
$to = $pages;
if(($to - $from) < $page && ($to - $from) < $pages) {
$from = $pages - $page + 1;
}
}
}
if($from==2){
$multipage .= "<li><a href=\"".$url."page=1\">1</a></li>";
}
if($from>2){
$multipage .= "<li><a href=\"".$url."page=1\">1</a></li>... ";
}
for($i = $from; $i <= $to; $i++) {
if($i != $curr_page) {
$multipage .= "<li><a href=\"".$url."page=$i\">$i</a></li> ";
}
else {
$multipage .= '<li>'.$i.'</li>';
}
}
if($to<$pages-1){
$multipage.=" ... <li><a href=\"".$url."page=$pages\">$pages</a></li>";
}
if($to==$pages-1){
$multipage.="<li><a href=\"".$url."page=$pages\">$pages</a></li>";
}
}
return $multipage;
}
有点类似于discuz论坛的分页。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询