当前位置:编程学习 > php >>

php中分页显示文章标题

php中文章标题很多的情况下怎样才能分页显示呢?
  下面根据本人的体会把主要代码公开,希望对初学网友有所帮助.
$page_size=10;(每页显示数量)
$sql='select count(*) as rnt from mydbf';
$sql .= ' order by mytime desc ';
$qh=mysql_query($sql);
$data=mysql_fetch_array($qh);
$nr=$data["cnt"];
$pages=intval($nr/$page_size);
if($nr%$page_size) $pages ;
if(empty($page))
{
$page=1;
$offset=0;
}
else
{
$offset=$page*$page_size-$page_size;
}
?>
<!--
$total = mysql_numrows($qh);
$total=$nr;
echo "<td colspan=3>";
//显示所有文章
if (!isset($page)){
$page = 0;
}
//分页开始
$start= $page*$page_size;
$offset=$start;
$totalpage =ceil($total/$page_size);
$pagestr ='[<font color=green>总数</font>]:'.$total;
$pagestr.= " ".($page 1).'/'.$totalpage.'页'." ";
$xjz1= "<a href=$php_self?";
$sql = 'select mytxt,content_id,clicknum,from mydbf ';
$sql .= ' order by ltime desc limit '.$offset.','.$pageno;
$res = mysql_query($ls_sql, $dbh); 
$countloop = 0;
while ($row = mysql_fetch_array($res)) { 
....
}
$xjz1= "<a href=$php_self?";
$xjz2=substr($xjz1,8);
?>
<table border="0" width="100%" cellpadding="0" cellspacing="0" height="0">
<form action="<?echo $php_self.$xjz2."&page=$page";?>" method="post">
<td width="100%" height="9"> 
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr><td width="72%" align="center" nowrap> <b>分页</b>:<?if($page==1){?>首页 
上一页 <?
   }
   else
   {
   $p=$page-1;
   echo "$xjz1&page=1>首页</a> $xjz1&page=$p>上一页</a>";
补充:Php教程,Php常用代码
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,