日期:2014-05-17  浏览次数:20410 次

关于分页及URL的请教
现在遇到的一个关于分页传值的问题,sql语句做了限制条件 $sql="select * from record where searchtime between '$date1' and '$date2'";
当提交这个表单后,刚搜索时结果是正确的,但是进行翻页时就会变为 $sql="select * from record"的第二页

通过在网上查询,得知需要做url传值? 这个不是很明白,能不能在我的这个源码下 详细讲下这方面的知识啊?

源代码如下:

PHP code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>搜索页面</title>
</head>

<body>
<form name="form2" method="post" action="search.php">
<div align="center">
<table width="1230" height="103" border="0" align="left" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC"> 
<tr> 
<!-- 将要列出的内容-->
<th width="4" height="38" bgcolor="#E3E3E3" scope="col">登记</th> 
<th width="30" bgcolor="#E3E3E3" scope="col">NO.</th> 
<th width="80" bgcolor="#E3E3E3" scope="col">用户号码</th>
<th width="80" bgcolor="#E3E3E3" scope="col">地址</th>
<th width="80" bgcolor="#E3E3E3" scope="col">行动</th>
<th width="80" bgcolor="#E3E3E3" scope="col">到达时间</th>
<th width="80" bgcolor="#E3E3E3" scope="col">出发时间</th>
<th width="80" bgcolor="#E3E3E3" scope="col">距离</th>
<th width="80" bgcolor="#E3E3E3" scope="col">邮件</th>
<th width="80" bgcolor="#E3E3E3" scope="col">接到邮件用时</th>
<th width="80" bgcolor="#E3E3E3" scope="col">误发邮件</th>
<th width="80" bgcolor="#E3E3E3" scope="col">发信邮箱</th>
<th width="80" bgcolor="#E3E3E3" scope="col">机器</th>
</tr> 
<?php
$link=mysql_connect('localhost','root','mysql');  //数据库用户名及数据库密码
mysql_select_db('BERecord');  //数据库名称
mysql_query('set names utf8');

$Page_size=10;  //设置每页显示个数
if(!empty($date1) || !empty($date2)){
$result=mysql_query("select * from record where searchtime between '$date1' and '$date2'");   
}//record为表名
else if(!empty($date1)){
$result=mysql_query("select * from record where searchtime > '$date1'");
}
else if(!empty($date2)){
$result=mysql_query("select * from record where searchtime < '$date2'");
}
else {
$result=mysql_query("select * from record");
}
$count = mysql_num_rows($result);
$page_count = ceil($count/$Page_size);

$init = 1;
$page_len = 7;
$max_p=$page_count;
$pages=$page_count;

//判断当前页码
if(empty($_GET['page'])||$_GET['page']<0){
$page=1;
}
else{
$page=$_GET['page'];
}

$offset=$Page_size*($page-1);
//if(!$date1 || !$date2)
if($date1 != "" && $date2 != ""){
$sql="select * from record where searchtime between '$date1' and '$date2' limit $offset,$Page_size";
}
else if($date1 != ""  ){
$sql="select * from record where searchtime > '$date1'";
}
else if($date2 != ""){
$sql="select * from record where searchtime < '$date2'";
}
else{
$sql="select * from record limit $offset,$Page_size";
}
$result=mysql_query($sql,$link);
//$row=mysql_fetch_array($result);       
while($row=mysql_fetch_array($result)){
?>
<tr> 
<td bgcolor="#E0EEE0" height="25px"><div align="center"> 
<?php echo