php分页错误
$pagesize=10;$url=$_SERVER["REQUEST_URI"];$url=parse_url($url);$url=$url[path];$newq=...
$pagesize=10;
$url=$_SERVER["REQUEST_URI"];
$url=parse_url($url);
$url=$url[path];
$newq=$db->selectall("zf_baike");
$newrows=$db->num_rows($newq);
echo $newrows;
if($_GET[page]){
$pageval=$_GET[page];
$page=($pageval-1)*$pagesize;
}
if($newrows>$pagesize){
if($pageval<=0) $pageval=1;
echo "<a href=$url?page=".($pageval-1).">previous</a> <a href=$url?page=".($pageval+1).">next</a>";
}
echo $page."=".$pageval;
$result_news_1=$db->selectall("sql_news limit $page,$pagesize");
找不出错误 展开
$url=$_SERVER["REQUEST_URI"];
$url=parse_url($url);
$url=$url[path];
$newq=$db->selectall("zf_baike");
$newrows=$db->num_rows($newq);
echo $newrows;
if($_GET[page]){
$pageval=$_GET[page];
$page=($pageval-1)*$pagesize;
}
if($newrows>$pagesize){
if($pageval<=0) $pageval=1;
echo "<a href=$url?page=".($pageval-1).">previous</a> <a href=$url?page=".($pageval+1).">next</a>";
}
echo $page."=".$pageval;
$result_news_1=$db->selectall("sql_news limit $page,$pagesize");
找不出错误 展开
2个回答
展开全部
<?php
$page=1;
if(@$_GET['page']){
$page=@$_GET['page'];
}
else{
$page=1;
}
$server=mysql_connect("127.0.0.1",'root','0000');
mysql_select_db("php",$server);
mysql_query("set names utf8");
//每页显示的行数
$pageSize=5;
//根据页数、每页显示的行数,来计算表中的行号$pageOffset=($page-1)*$pageSize;
//表中数据的总记录数$total=mysql_num_rows(mysql_query("select * from fy"));
$endpage= ceil($total/$pageSize);
if($page>$endpage)
$page=$endpage;
else if($page<=1)
$page=1;
$result=mysql_query("select * from fy limit $pageOffset,$pageSize");
//遍历结果集,获得表中的行数据的二维数组
$arr=array();
while($row=mysql_fetch_assoc($result)){
$arr[]=$row;
}
?>
<html>
<head>
<title>分页</title>
<form action="page2.php" method="get">
<input type="text" name="title">
<input type="submit" value="so">
<script language="javascript" src="jquery.js"></script>
</head>
<div id='mydiv'>
<table border=1 width=60%>
<th>编号</th><th>文章标题</th><th>文章内容</th>
<?php foreach($arr as $key=>$val) { ?>
<tr align=center>
<td><?php echo $val['id']; ?></td>
<td><?php echo $val['name']; ?></td>
<td><?php echo $val['age']; ?></td>
</tr>
<?php }
$shang="list_".($page-1).".html";
?>
<form>
<tr><td colspan=5>
<span>共<?php echo $total; ?>条数据</span>
<a href="page.php?page=1">首页</a>
<a href="<?php echo $shang?>">上一页</a>
<?php
if($page==$endpage){
echo '下一页';
}
else{
$page+=1;
$xia="list_".$page.".html";
echo "<a href='$xia'>下一页</a> ";
}
?>
<a href="page.php?page=<?php echo $endpage; ?>">尾页</a></td>
</tr>
</table>
</div>
</html>
用这个把
$page=1;
if(@$_GET['page']){
$page=@$_GET['page'];
}
else{
$page=1;
}
$server=mysql_connect("127.0.0.1",'root','0000');
mysql_select_db("php",$server);
mysql_query("set names utf8");
//每页显示的行数
$pageSize=5;
//根据页数、每页显示的行数,来计算表中的行号$pageOffset=($page-1)*$pageSize;
//表中数据的总记录数$total=mysql_num_rows(mysql_query("select * from fy"));
$endpage= ceil($total/$pageSize);
if($page>$endpage)
$page=$endpage;
else if($page<=1)
$page=1;
$result=mysql_query("select * from fy limit $pageOffset,$pageSize");
//遍历结果集,获得表中的行数据的二维数组
$arr=array();
while($row=mysql_fetch_assoc($result)){
$arr[]=$row;
}
?>
<html>
<head>
<title>分页</title>
<form action="page2.php" method="get">
<input type="text" name="title">
<input type="submit" value="so">
<script language="javascript" src="jquery.js"></script>
</head>
<div id='mydiv'>
<table border=1 width=60%>
<th>编号</th><th>文章标题</th><th>文章内容</th>
<?php foreach($arr as $key=>$val) { ?>
<tr align=center>
<td><?php echo $val['id']; ?></td>
<td><?php echo $val['name']; ?></td>
<td><?php echo $val['age']; ?></td>
</tr>
<?php }
$shang="list_".($page-1).".html";
?>
<form>
<tr><td colspan=5>
<span>共<?php echo $total; ?>条数据</span>
<a href="page.php?page=1">首页</a>
<a href="<?php echo $shang?>">上一页</a>
<?php
if($page==$endpage){
echo '下一页';
}
else{
$page+=1;
$xia="list_".$page.".html";
echo "<a href='$xia'>下一页</a> ";
}
?>
<a href="page.php?page=<?php echo $endpage; ?>">尾页</a></td>
</tr>
</table>
</div>
</html>
用这个把
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询