帮忙看一下我的分页程序! 终于看完了,好乱的代码。说实话,没看出问题,不过可以给点改进建议。是不是可以把if(isset($nextpage))呢?说不定有奇效呢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 ###########设定SQL查询语句中的初始记录值######################## $start_rowno=($pageno-1)*$pagesize;//$start_rowno为每页开始ID号 //进行SQL查询,提取出指定长度的记录数 $query="select count(*) from liuyan526 order by ID DESC LIMIT ".$start_rowno.",".$pagesize; $result=mysql_query($query,$link) or die('SQL出错!'); // $num_rows=mysql_num_rows($result); //$nextpage代表是否还有下一页.若有,则值为1$num=mysql_fetch_array($result); $num_row=$num[count]; $totalpage=ceil($num_row/$pagesize);//$pagesize指定每页显示的记录数,在 //config.inc.php中应有设定 } $totalpage=(int)$totalpage; //$nextpage=0; if($totalpage>=$pageno); { $nextpage=1; } //显示留言信息 还是不行,我又换了一种方式分页,在网上找几个例子,可是不知道设置$offset是什么用?程序代码如下<?require("config.inc.php");require("head.php");$firstpage="<";$lastpage=">";mysql_connect($host,$dbuser,$dbpass);mysql_select_db($db);$sql="select count(*) as count from liuyan526 order by id desc";$liuyan_nums=mysql_fetch_array(mysql_query($sql));$nums=$liuyan_nums[count];if (empty($offset)) { $offset=0; } $sql="select * from liuyan526 order by id desc limit $offset,4";$query=mysql_query($sql);while($array=mysql_fetch_array($query)){ echo $array[name]; echo "<br>"; echo $array[email]; echo "<br>"; echo $array[comment]; echo "<br>"; echo "<hr>";}//下一步,要写出到其它页面的链接 if($offset) //如果偏移量是0,不显示前一页的链接 { $preoffset=0; print "<a href=\"$PHP_SELF?offset=$preoffset\">$firstpage</a> \n"; } //计算总共需要的页数 $pages=ceil($nums/4); //$pages变量现在包含所需的页数 for ($i=1; $i<=$pages;$i++) { $newoffset=$i; print "<a href=\"$PHP_SELF?offset=$newoffset\">$i</a> \n"; } //检查是否是最后一页 if ($offset) { print "<a href=\"$PHP_SELF?offset=$newoffset\">$lastpage</a> \n"; } ?> 看看,,太乱了,,$sql="select * from liuyan526 order by id desc limit $offset,4";这是说从$offset行号开始,显示4条记录 关于PHP GET传参乱码的问题 留言板编辑留言的权限问题 mysql 数据储存乱码问题 从提交的内容里取出图片上传和取出地址 寻找PHP安装目录下的libmysql.dll 我这样写有语法错误? 匹配字符串 php 用ODBC方式接连MSSQL 时出错 各位老兄有没有考虑一个程序员以后的发展方向?大家来设计设计!这是每个程序员必须考虑的。 获取文本中第一张符合尺寸的图片地址 帮我看一下自动刷新的问题 求助!!!
$start_rowno=($pageno-1)*$pagesize;//$start_rowno为每页开始ID号
//进行SQL查询,提取出指定长度的记录数
$query="select count(*) from liuyan526
order by ID DESC
LIMIT ".$start_rowno.",".$pagesize;
$result=mysql_query($query,$link) or die('SQL出错!');
// $num_rows=mysql_num_rows($result);
//$nextpage代表是否还有下一页.若有,则值为1
$num=mysql_fetch_array($result);
$num_row=$num[count];
$totalpage=ceil($num_row/$pagesize);//$pagesize指定每页显示的记录数,在 //config.inc.php中应有设定
}
$totalpage=(int)$totalpage;
//$nextpage=0;
if($totalpage>=$pageno);
{
$nextpage=1;
}
//显示留言信息
<?
require("config.inc.php");
require("head.php");
$firstpage="<";
$lastpage=">";
mysql_connect($host,$dbuser,$dbpass);
mysql_select_db($db);
$sql="select count(*) as count from liuyan526 order by id desc";
$liuyan_nums=mysql_fetch_array(mysql_query($sql));
$nums=$liuyan_nums[count];if (empty($offset))
{
$offset=0;
} $sql="select * from liuyan526 order by id desc limit $offset,4";
$query=mysql_query($sql);
while($array=mysql_fetch_array($query))
{
echo $array[name];
echo "<br>";
echo $array[email];
echo "<br>";
echo $array[comment];
echo "<br>";
echo "<hr>";
}
//下一步,要写出到其它页面的链接
if($offset) //如果偏移量是0,不显示前一页的链接
{
$preoffset=0;
print "<a href=\"$PHP_SELF?offset=$preoffset\">$firstpage</a> \n";
} //计算总共需要的页数 $pages=ceil($nums/4); //$pages变量现在包含所需的页数 for ($i=1; $i<=$pages;$i++)
{
$newoffset=$i;
print "<a href=\"$PHP_SELF?offset=$newoffset\">$i</a> \n";
} //检查是否是最后一页 if ($offset)
{
print "<a href=\"$PHP_SELF?offset=$newoffset\">$lastpage</a> \n";
} ?>
$sql="select * from liuyan526 order by id desc limit $offset,4";
这是说从$offset行号开始,显示4条记录