PHP分页那里错了
ttt是表tt是表格<?phpmysql_connect("localhost","root",'3277');mysql_select_db("ttt");$page=...
ttt是表 tt是表格
<?php
mysql_connect("localhost","root",'3277');
mysql_select_db("ttt");
$page=isset($_GET["page"])?$_GET['page']:1; //当前页
$pagesize=3 ;//页大小
$maxRows;
$maxpages;
$sql="select count(*) from tt";
$res=mysql_query($sql);
$maxRows=mysql_result($res,0,0);
$maxpages=ceil($maxRows/$pagesize);
if($page>$maxpages){ $page=$maxpages; }
if($page<1){ $page=1; }
$limit="limit".(($page-1)*$pagesize).",{$pagesize}";
$sql="select * from tt order by id desc{$limit}";
$result=mysql_query($sql);
while($val=mysql_fetch_assoc($result))
{
echo "<tr>";
echo "<td>".$val['title']."</td>";
echo "<td>".$val['nei']."</td>";
echo "<td><a href='javascript:a({$val['id']})'>删除</a></td>";
echo "<td><a href='javascript:b({$val['id']})'>修改</a></td>";
echo "</tr>";
}
echo "当前{$page}/{$maxpages}页 共计{$maxRows}";
echo "<a href='a.php?page=1'>第一页 </a>";
echo "<a href='a.php?page=".($page-1)."'>下一页 </a>";
echo "<a href='a.php?page=".($page+1)."'>上一页 </a>";
echo "<a href='a.php?page={$maxpages}'>尾页 </a>";
?>
错误提示
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\a.php on line 60 展开
<?php
mysql_connect("localhost","root",'3277');
mysql_select_db("ttt");
$page=isset($_GET["page"])?$_GET['page']:1; //当前页
$pagesize=3 ;//页大小
$maxRows;
$maxpages;
$sql="select count(*) from tt";
$res=mysql_query($sql);
$maxRows=mysql_result($res,0,0);
$maxpages=ceil($maxRows/$pagesize);
if($page>$maxpages){ $page=$maxpages; }
if($page<1){ $page=1; }
$limit="limit".(($page-1)*$pagesize).",{$pagesize}";
$sql="select * from tt order by id desc{$limit}";
$result=mysql_query($sql);
while($val=mysql_fetch_assoc($result))
{
echo "<tr>";
echo "<td>".$val['title']."</td>";
echo "<td>".$val['nei']."</td>";
echo "<td><a href='javascript:a({$val['id']})'>删除</a></td>";
echo "<td><a href='javascript:b({$val['id']})'>修改</a></td>";
echo "</tr>";
}
echo "当前{$page}/{$maxpages}页 共计{$maxRows}";
echo "<a href='a.php?page=1'>第一页 </a>";
echo "<a href='a.php?page=".($page-1)."'>下一页 </a>";
echo "<a href='a.php?page=".($page+1)."'>上一页 </a>";
echo "<a href='a.php?page={$maxpages}'>尾页 </a>";
?>
错误提示
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\a.php on line 60 展开
2个回答
展开全部
/**
* 页码转sql
*
* @param int $page 分页,$_GET['page']
* @param int $perpage 每页显示数数量
* @return array <1.start 2.limit>
*/
public static function page2limit($page, $perpage = 10) {
$limit = intval($perpage);
$start = max(($page - 1) * $limit, 0);
return array($start, $limit);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询