主题:  分页怎么了?

sunslee

职务:普通成员
等级:1
金币:0.0
发贴:107
#12004/11/2 16:19:33
<?
    $pagesize=1;    //pagesize为每页现实记录条数。
    genpage($sql,$pagesize); //只需要正常代码加上这一行就ok。
    $sql="select * from expo order by expoid desc";
    $result=mysql_query($sql);
    $num_results=mysql_num_rows($result);
while($row=mysql_fetch_array($result))
     {
        $id= htmlspecialchars(stripslashes($row["expoid"]));
        echo "<tr bgcolor='#E8E8E8' onMouseOver=this.bgColor='#E6F8FF'; onMouseOut=this.bgColor='#E8E8E8';>";
        echo "<td class='content'>"."&nbsp;&nbsp;";
        echo "<a href=javascript:winopen('listallexpo.php?num_results=$num_results&id=$id') class='normallink'>";
        echo htmlspecialchars(stripslashes($row["expotitle"]))."</a>"."</td>";
        echo "<td class='content'>"."&nbsp;&nbsp;";
        echo htmlspecialchars(stripslashes($row["expodate1"]))."&nbsp;至&nbsp;".htmlspecialchars(stripslashes($row["expodate2"]))."</td>";
        echo "</tr>";
    }
?>



<?
//分页函数

function genpage(&$sql,$page_size)
{
global $prepage,$nextpage,$pages,$sums; //out param
$page = $_GET["page"];
$eachpage = $page_size;
$pagesql = strstr($sql," from ";
$pagesql = "select count(*) as ids ".$pagesql;
$result = mysql_query($pagesql);
if($rs = mysql_fetch_array($result)) $sums = $rs[0];
$pages = ceil(($sums-0.5)/$eachpage)-1;
$pages = $pages>=0?$pages:0;
$prepage = ($page>0)?$page-1:0;
$nextpage = ($page<$pages)?$page+1:$pages;
$startpos = $page*$eachpage;
$sql .=" limit $startpos,$eachpage ";
}
//显示分页
function showpage()
{
global $page,$pages,$prepage,$nextpage,$queryString; //param from genpage function
$shownum =10/2;
$startpage = ($page>=$shownum)?$page-$shownum:0;
$endpage = ($page+$shownum<=$pages)?$page+$shownum:$pages;

echo "共".($pages+1)."页:&nbsp;";
if($page>0)echo "<a href=$PHP_SELF?page=0&$queryString>第一页</a>";
if($startpage>0)
echo " ... <b><a href=$PHP_SELF?page=".($page-$shownum*2)."&$queryString>&laquo;</a></b>";
for($i=$startpage;$i<=$endpage;$i++)
{
if($i==$page) echo "&nbsp;<b>[".($i+1)."]</b>&nbsp;";
else echo "&nbsp;<a href=$PHP_SELF?page=$i&$queryString>".($i+1)."</a>&nbsp;";
}
if($endpage<$pages)
echo "<b><a href=$PHP_SELF?page=".($page+$shownum*2)."&$queryString>&raquo;</a></b> ... ";
if($page<$pages)
echo "<a href=$PHP_SELF?page=$pages&$queryString>最后页</a>";

}
?>



sunslee

职务:普通成员
等级:1
金币:0.0
发贴:107
#22004/11/2 16:23:54
为什么不能控制显示的记录条数啊



Mike

职务:版主
等级:6
金币:11.0
发贴:5148
#32004/11/7 12:10:18
次序不对



asrther234

职务:普通成员
等级:1
金币:0.0
发贴:1
#42004/11/14 15:49:19
dsfasdfadsf