PHP+MYSQL查询分页显示问题
<center><formname="form1"method="post"action="search.php"><tablecellspacing="0"cellpa...
<center><form name="form1" method="post" action="search.php">
<table cellspacing="0" cellpadding="0">
<tr>
<td>
<input type="text" name="keyword">
</td>
<td><input type="submit" name="Submit" value="搜索"></td>
</tr>
</table>
<a href="index.php">首页</a> <a href="admin_login.htm" target="_blank">管理员登录</a>
</form></center>
</body>
<?php
include_once("include/defance.php");
include_once("include/db.inc.php");
$pagesize=23;
$keyword = isset($_REQUEST['keyword']) ? $_REQUEST['keyword'] : '';
$rs=mysql_query("Select count(*) From TABLE_HRD_CONTACTS_V01 Where COL_CALL='$keyword' or COL_EQSL_QSLSDATE='$keyword' or COL_MODE='$keyword' or COL_MODE='$keyword' or COL_RST_SENT='$keyword' or COL_RST_RCVD='$keyword' or COL_BAND='$keyword' or COL_COUNTRY='$keyword'",$conn);
$myrow = mysql_fetch_array($rs);
$numrows=$myrow[0];
$pages=intval($numrows/$pagesize);
if($numrows%$pagesize)
$pages++;
if(isset($_REQUEST['page'])){
$page=intval($_REQUEST['page']);
}
else
{
$page=1;
}
$offset=$pagesize*($page - 1);
$rs=mysql_query("select * from table_hrd_contacts_v01 Where COL_CALL='$keyword' or COL_EQSL_QSLSDATE='$keyword' or COL_MODE='$keyword' or COL_MODE='$keyword' or COL_RST_SENT='$keyword' or COL_RST_RCVD='$keyword' or COL_BAND='$keyword' or COL_COUNTRY='$keyword' limit $offset,$pagesize",$conn);
if($myrow = mysql_fetch_array($rs))
{
$i=0;
?>
<?php
if (!empty($keyword)&&mysql_num_rows($rs)<>0){
?>
<table width="900" height="50" border="1" align="center">
<tr>
<td>QSO data</td>
<td>Time on</td>
<td>Call</td>
<td>Mode</td>
<td>Sent</td>
<td>Rcvd</td>
<td>Band</td>
<td>Name</td>
<td>Country</td>
</tr>
<?php
do{
$i++;
?>
<tr>
<td><?php echo $myrow[COL_EQSL_QSLSDATE];?></td>
<td><?php echo $myrow[COL_TIME_ON];?></td>
<td><?php echo $myrow[COL_CALL];?></td>
<td><?php echo $myrow[COL_MODE];?></td>
<td><?php echo $myrow[COL_RST_SENT];?></td>
<td><?php echo $myrow[COL_RST_RCVD];?></td>
<td><?php echo $myrow[COL_BAND];?></td>
<td><?php echo $myrow[COL_MY_NAME];?></td>
<td><?php echo $myrow[COL_COUNTRY];?></td>
</tr>
<?php
}
while ($myrow = mysql_fetch_array($rs));
echo "</table>";
}
?>
<center>现在是第<?php echo $page;?>页,共<?php echo $pages;?>页
<a href="?pages=1">首页</a>
<a href="?page=<?php if($page>1){echo $page-1;}else{echo 1;}?>">前一页</a>
<a href="?page=<?php if($page<$pages){echo $page+1;}else{echo $pages;}?>">后一页</a>
<a href="?page=<?php echo $pages;?>">末页</a></center>
<?php
mysql_close($conn);
}
else
{
echo "<script>alert('此查询无效,请重新输入!');</script>";
}
?>
查询正确,分页显示正确,只是没点下一页或者上一页或者首页或者末页的时候,会弹出:重新输入的对话框,真正明白的来,网上很多代码我都看过了,人云亦云的请GUN!!
我知道是分页的最后页数那里出了问题,应该是传递的值有问题,不过真心不知道怎么改。 展开
<table cellspacing="0" cellpadding="0">
<tr>
<td>
<input type="text" name="keyword">
</td>
<td><input type="submit" name="Submit" value="搜索"></td>
</tr>
</table>
<a href="index.php">首页</a> <a href="admin_login.htm" target="_blank">管理员登录</a>
</form></center>
</body>
<?php
include_once("include/defance.php");
include_once("include/db.inc.php");
$pagesize=23;
$keyword = isset($_REQUEST['keyword']) ? $_REQUEST['keyword'] : '';
$rs=mysql_query("Select count(*) From TABLE_HRD_CONTACTS_V01 Where COL_CALL='$keyword' or COL_EQSL_QSLSDATE='$keyword' or COL_MODE='$keyword' or COL_MODE='$keyword' or COL_RST_SENT='$keyword' or COL_RST_RCVD='$keyword' or COL_BAND='$keyword' or COL_COUNTRY='$keyword'",$conn);
$myrow = mysql_fetch_array($rs);
$numrows=$myrow[0];
$pages=intval($numrows/$pagesize);
if($numrows%$pagesize)
$pages++;
if(isset($_REQUEST['page'])){
$page=intval($_REQUEST['page']);
}
else
{
$page=1;
}
$offset=$pagesize*($page - 1);
$rs=mysql_query("select * from table_hrd_contacts_v01 Where COL_CALL='$keyword' or COL_EQSL_QSLSDATE='$keyword' or COL_MODE='$keyword' or COL_MODE='$keyword' or COL_RST_SENT='$keyword' or COL_RST_RCVD='$keyword' or COL_BAND='$keyword' or COL_COUNTRY='$keyword' limit $offset,$pagesize",$conn);
if($myrow = mysql_fetch_array($rs))
{
$i=0;
?>
<?php
if (!empty($keyword)&&mysql_num_rows($rs)<>0){
?>
<table width="900" height="50" border="1" align="center">
<tr>
<td>QSO data</td>
<td>Time on</td>
<td>Call</td>
<td>Mode</td>
<td>Sent</td>
<td>Rcvd</td>
<td>Band</td>
<td>Name</td>
<td>Country</td>
</tr>
<?php
do{
$i++;
?>
<tr>
<td><?php echo $myrow[COL_EQSL_QSLSDATE];?></td>
<td><?php echo $myrow[COL_TIME_ON];?></td>
<td><?php echo $myrow[COL_CALL];?></td>
<td><?php echo $myrow[COL_MODE];?></td>
<td><?php echo $myrow[COL_RST_SENT];?></td>
<td><?php echo $myrow[COL_RST_RCVD];?></td>
<td><?php echo $myrow[COL_BAND];?></td>
<td><?php echo $myrow[COL_MY_NAME];?></td>
<td><?php echo $myrow[COL_COUNTRY];?></td>
</tr>
<?php
}
while ($myrow = mysql_fetch_array($rs));
echo "</table>";
}
?>
<center>现在是第<?php echo $page;?>页,共<?php echo $pages;?>页
<a href="?pages=1">首页</a>
<a href="?page=<?php if($page>1){echo $page-1;}else{echo 1;}?>">前一页</a>
<a href="?page=<?php if($page<$pages){echo $page+1;}else{echo $pages;}?>">后一页</a>
<a href="?page=<?php echo $pages;?>">末页</a></center>
<?php
mysql_close($conn);
}
else
{
echo "<script>alert('此查询无效,请重新输入!');</script>";
}
?>
查询正确,分页显示正确,只是没点下一页或者上一页或者首页或者末页的时候,会弹出:重新输入的对话框,真正明白的来,网上很多代码我都看过了,人云亦云的请GUN!!
我知道是分页的最后页数那里出了问题,应该是传递的值有问题,不过真心不知道怎么改。 展开
4个回答
展开全部
$keyword = isset($_REQUEST['keyword']) ? $_REQUEST['keyword'] : '';
if (!empty($keyword)&&mysql_num_rows($rs)<>0) //$keyword未传递,为空,条件不成立
<a href="?pages=1">首页</a>
<a href="?page=<?php if($page>1){echo $page-1;}else{echo 1;}?>">前一页</a>
<a href="?page=<?php if($page<$pages){echo $page+1;}else{echo $pages;}?>">后一页</a>
<a href="?page=<?php echo $pages;?>">末页</a></center>
点击下一页$keyword为空,没有传递
<a href="?pages=1&keyword=<?php echo $keyword; ?>">首页</a>
以下同理
if (!empty($keyword)&&mysql_num_rows($rs)<>0) //$keyword未传递,为空,条件不成立
<a href="?pages=1">首页</a>
<a href="?page=<?php if($page>1){echo $page-1;}else{echo 1;}?>">前一页</a>
<a href="?page=<?php if($page<$pages){echo $page+1;}else{echo $pages;}?>">后一页</a>
<a href="?page=<?php echo $pages;?>">末页</a></center>
点击下一页$keyword为空,没有传递
<a href="?pages=1&keyword=<?php echo $keyword; ?>">首页</a>
以下同理
展开全部
治标不治本的方法!
最好的办法就是去掉下面这些代码即可,包准不会弹出框了!
else
{
echo "<script>alert('此查询无效,请重新输入!');</script>";
}
最好的办法就是去掉下面这些代码即可,包准不会弹出框了!
else
{
echo "<script>alert('此查询无效,请重新输入!');</script>";
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
去掉
else
{
echo "<script>alert('此查询无效,请重新输入!');</script>";
}
else
{
echo "<script>alert('此查询无效,请重新输入!');</script>";
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
a标签的地址写对了么 ?前面的地址不写没问题么?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询