php查询结果分页显示,字数受限,html头尾就不写了,请帮看下为何实现不了如图所示效果,分页按钮不起作用
<tablewidth="500"border="1"cellpadding="0"cellspacing="0"bgcolor="#CEFFCE"><tr><tdwid...
<table width="500" border="1" cellpadding="0" cellspacing="0" bgcolor="#CEFFCE">
<tr>
<td width="100" height="25" align="center"><span class="STYLE1">姓名</span></td>
<td width="100" align="center"><span class="STYLE1">编号</span></td>
<td width="125" align="center"><span class="STYLE1">电话</span></td>
<td width="175" align="center"><span class="STYLE1">地址</span></td>
</tr>
<?php
include "conn.php";
if ($page=="") {$page=1;};
if ($ljjl=="") {$ljjl=0;};
if($page){
$page_size=1;
$query="select count(*) as total from test1 where id";
$result=mysql_query($query);
$message_count=mysql_result($result,0,"total");
$page_count=ceil($message_count/$page_size);
$offset=($page-1)*$page_size;
$query="select * from test1 where id order by id desc limit $offset, $page_size";
$result=mysql_query($query);
while ($myrow=mysql_fetch_array($result)){
?>
<tr>
<td height="25" align="center" class="STYLE1"><?php echo $myrow[name];?></td>
<td align="center" class="STYLE1"><?php echo $myrow[number];?></td>
<td align="center" class="STYLE1"><?php echo $myrow[tel];?></td>
<td align="center" class="STYLE1"><?php echo $myrow[address];?></td>
</tr>
<?php }}?>
</table>
<table width="500" border="1" cellpadding="0" cellspacing="0" bgcolor="#CEFFCE">
<tr>
<td width="45%" height="22" align="center"><span class="STYLE2"> 页次:<?php echo $page;?>/<?php echo $page_count;?> 页 记录:<?php echo $message_count;?> 条 </span></td>
<td width="45%" align="center"><span class="STYLE2"> 分页:
<?php
$xsoudh="id=$id";
$next=$ljjl*10;
$n=$ljjl-1;
$m=$ljjl+1;
$prev_page=$page-10;
if ($ljjl==0){echo "<width=\"8\" height=\"9\" title=\"首页\">";}
else{echo "<a href='$PATH_INFO?vv=0&ljjl=0&page=1&$xsoudh'><width=\"8\" height=\"9\" border=\"0\" title=\"首页\"></a> ";
$ccc=$vv-10;
echo "<a href='$PATH_INFO?vv=$ccc&ljjl=$n&page=$prev_page&$xsoudh'><width=\"8\" height=\"9\" title=\"上十页\"></a>";}
?>
<?php
for ($j=1;$j<=$page_count;$j++) {
$pnext=$next+$j;
if ($mm==10){break;}
if ($mm>$page_count){break;}
if ($page_count-$vv<10){
if ($mm>=$page_count-$vv){break;}
}
?>
<?php
echo "<a href='$PATH_INFO?vv=$vv&ljjl=$ljjl&page=$pnext&$xsoudh'> $pnext </a>";
$mm=$mm+1;
}
?>
</span></td>
<td width="10%" align="center">
<span class="STYLE2">
<?php
$vv=$vv+$mm;
if ($page_count-$vv<=0){echo "<width=\"8\" height=\"9\" title=\"尾页\">";}
else{echo "<a href='$PATH_INFO?vv=$vv&ljjl=$m&page=$pnext&$xsoudh'><width=\"8\" height=\"9\" title=\"下十页\"></a>";}
if ($message_count==0){echo "没有记录!";}
?>
</span></td></tr></table>
test1表结构:id,name,number,tel,address
上述代码能够实现分页,但是点击每个分页按钮都只显示第一页的查询内容,我怀疑是页面间的值传递出现了问题,请高手帮忙看看 展开
<tr>
<td width="100" height="25" align="center"><span class="STYLE1">姓名</span></td>
<td width="100" align="center"><span class="STYLE1">编号</span></td>
<td width="125" align="center"><span class="STYLE1">电话</span></td>
<td width="175" align="center"><span class="STYLE1">地址</span></td>
</tr>
<?php
include "conn.php";
if ($page=="") {$page=1;};
if ($ljjl=="") {$ljjl=0;};
if($page){
$page_size=1;
$query="select count(*) as total from test1 where id";
$result=mysql_query($query);
$message_count=mysql_result($result,0,"total");
$page_count=ceil($message_count/$page_size);
$offset=($page-1)*$page_size;
$query="select * from test1 where id order by id desc limit $offset, $page_size";
$result=mysql_query($query);
while ($myrow=mysql_fetch_array($result)){
?>
<tr>
<td height="25" align="center" class="STYLE1"><?php echo $myrow[name];?></td>
<td align="center" class="STYLE1"><?php echo $myrow[number];?></td>
<td align="center" class="STYLE1"><?php echo $myrow[tel];?></td>
<td align="center" class="STYLE1"><?php echo $myrow[address];?></td>
</tr>
<?php }}?>
</table>
<table width="500" border="1" cellpadding="0" cellspacing="0" bgcolor="#CEFFCE">
<tr>
<td width="45%" height="22" align="center"><span class="STYLE2"> 页次:<?php echo $page;?>/<?php echo $page_count;?> 页 记录:<?php echo $message_count;?> 条 </span></td>
<td width="45%" align="center"><span class="STYLE2"> 分页:
<?php
$xsoudh="id=$id";
$next=$ljjl*10;
$n=$ljjl-1;
$m=$ljjl+1;
$prev_page=$page-10;
if ($ljjl==0){echo "<width=\"8\" height=\"9\" title=\"首页\">";}
else{echo "<a href='$PATH_INFO?vv=0&ljjl=0&page=1&$xsoudh'><width=\"8\" height=\"9\" border=\"0\" title=\"首页\"></a> ";
$ccc=$vv-10;
echo "<a href='$PATH_INFO?vv=$ccc&ljjl=$n&page=$prev_page&$xsoudh'><width=\"8\" height=\"9\" title=\"上十页\"></a>";}
?>
<?php
for ($j=1;$j<=$page_count;$j++) {
$pnext=$next+$j;
if ($mm==10){break;}
if ($mm>$page_count){break;}
if ($page_count-$vv<10){
if ($mm>=$page_count-$vv){break;}
}
?>
<?php
echo "<a href='$PATH_INFO?vv=$vv&ljjl=$ljjl&page=$pnext&$xsoudh'> $pnext </a>";
$mm=$mm+1;
}
?>
</span></td>
<td width="10%" align="center">
<span class="STYLE2">
<?php
$vv=$vv+$mm;
if ($page_count-$vv<=0){echo "<width=\"8\" height=\"9\" title=\"尾页\">";}
else{echo "<a href='$PATH_INFO?vv=$vv&ljjl=$m&page=$pnext&$xsoudh'><width=\"8\" height=\"9\" title=\"下十页\"></a>";}
if ($message_count==0){echo "没有记录!";}
?>
</span></td></tr></table>
test1表结构:id,name,number,tel,address
上述代码能够实现分页,但是点击每个分页按钮都只显示第一页的查询内容,我怀疑是页面间的值传递出现了问题,请高手帮忙看看 展开
4个回答
2011-12-27
展开全部
你那$query="select count(*) as total from test1 where id";
$result=mysql_query($query);
$message_count=mysql_result($result,0,"total");
$page_count=ceil($message_count/$page_size);
$offset=($page-1)*$page_size;
$query="select * from test1 where id order by id desc limit $offset, $page_size";
where id 然后呢??没了?
$result=mysql_query($query);
$message_count=mysql_result($result,0,"total");
$page_count=ceil($message_count/$page_size);
$offset=($page-1)*$page_size;
$query="select * from test1 where id order by id desc limit $offset, $page_size";
where id 然后呢??没了?
追问
笔误,where id 可以去掉的,不影响
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我测试是可以的啊,分页没有问题
更多追问追答
追问
可以看到分页按钮,但是只能看第一页,其它按钮不起作用
追答
不是啊,分页按钮是可以用的啊,可以分页
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
没接收$page参数吧?
$page = $_GET['page'];
if(!$page or $page == "")
{
}
$page = $_GET['page'];
if(!$page or $page == "")
{
}
追问
您说的对,我补上了,但是为什么首页和尾页两个按钮功能实现不了呢?
追答
理论上应该会实现的,你现在是个什么情况?点击链接到第几页?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-12-30
展开全部
没接收$page参数?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询