最简单的办法,就是分页哪栏你把它看做一个整体.比如说"上一页 1 2 3 4 5 6 7 8 下一页",在程序里构造这个分页的串,然后将其传给smarty就OK了.
.....
//setPage为一个分页处理函数,返回一个带链接的分页串
$strPage = setPage("list.php", $count,$start,$limit, $param);
//smarty将这个串传给模板.
$tpl->assign('splitPage',$strPage);
....如果需要,可以将这个函数给你.
.....
//setPage为一个分页处理函数,返回一个带链接的分页串
$strPage = setPage("list.php", $count,$start,$limit, $param);
//smarty将这个串传给模板.
$tpl->assign('splitPage',$strPage);
....如果需要,可以将这个函数给你.
$result = $dbc->getrsarray($sql);$Total_page = ceil($maxline/$result['rows']);
$This_page = $_GET['p'];
$StartPage = ($This_page - 1 ) * $maxline;
echo "总共有".count($result)."页,第".$This_page."页";$sql = "select name from a limit $StartPage,$maxline";
$result = $dbc->getrsarray($sql);for ($i=0;$i<count($result);$i++)
{
echo $result['name']."<BR>\n";
}
通常先计算总页数。然后再获得相应页数的数据。用limit。
总数据量m,每页数据量n,这样就有了总页数ceiling(m/n)
每次访问的时候传来页码index,取数据时sql语句里limit (index-1)*n,n即可
include_once("./include/dbconn.php");//自己写的数据库连接类
$dbc=new DbConn();//实例化类
$maxline=2;
$sql = "select count(*) as rows from a";
$rs=$dbc->getRs($sql);//得到一个结果集
$num=$rs['rows'];
$backurl="pagetest1.php";
/**
* $Total_page 总页数
* $maxline 每页显示多少行
* $This_page 当前是多少页
* $num 一共有多少条记录
* */
$Total_page = ceil($num/$maxline);
$This_page = $_REQUEST['page'];
if($This_page==0 ||$This_page=="")
{
$This_page=1;
}
//echo "This_page:".$This_page."<br>";
$StartPage = ($This_page - 1 ) * $maxline;
//echo "总共有".$Total_page."页,第".$This_page."页<br>"; $sql = "select name from a limit $StartPage,$maxline";
//echo "SQL:".$sql."<br>";
$result = $dbc->getRsArray($sql); $limit=array();
for($i=0;$i<$Total_page;$i++)
{
$limit[$i]=$i;
}$pagers=setResult($backurl,$This_page,$Total_page,$maxline,$limit);$smarty->assign("gotopage",$pagers);function setResult($url,$this_page,$total_page,$max,$Limit)
{
$allresult=array();
$allresult['url']=$url;
$allresult['this_pag']=$this_page;
$allresult['total_page']=$total_page;
$allresult['maxline']=$max;
$allresult['limit']=$Limit;
return $allresult;
}
?>
smarty 模板 那两个image图片就是上一页 下一页的图片
<div id="ClassTitle_01">
<div class="Class_page">
{$gotopage.this_page}/{$gotopage.total_page} 跳转到:
<select name="selectpage" onChange="location.href=this.value;">
{foreach item=item1 from=$gotopage.limit}
{if $item1+1 == $gotopage.this_page}
<option value="{$gotopage.url}?page={$item1+1}" selected>{$item1+1}</option>
{else}
<option value="{$gotopage.url}?page={$item1+1}">{$item1+1}</option>
{/if}
{/foreach}
</select>
共计{$gotopage.total}条记录
</div>
<div class="Class_page_btn">
{if $gotopage.this_page>1}
<a href="{$gotopage.url}?page={$gotopage.this_page-1}"><img src="images/classPagebtn2.gif" border="0"></a>
{else}
<img src="images/classPagebtn2.gif" border="0">
{/if}
{if $gotopage.this_page<$gotopage.total_page}
<a href="{$gotopage.url}?page={$gotopage.this_page+1}"><img src="images/classPagebtn2.gif" border="0"></a>
{else}
<img src="images/classPagebtn1.gif" border="0">
{/if}
</div>
</div>
哈哈~~我终于也能自己完成一块东西了!虽然写的很乱,但是总归是写出来了!谢谢各位师哥了!