跳页没带条件<?php
$search = $_GET['Town'];
$conn = mysql_connect("localhost","root","");
$maxnum = 50; //每页显示记录条数
mysql_select_db("db", $conn);
mysql_query("SET NAMES UTF8");
$query1 = "SELECT COUNT(*) AS totalrows FROM Sheet1 Where Town like '%$search%'";
$result1 = mysql_query($query1, $conn) or die(mysql_error());
$row1 = mysql_fetch_assoc($result1);
$totalRows1 = $row1['totalrows']; //数据集数据总条数
$totalpages = ceil($totalRows1/$maxnum);//计算可分页总数,ceil()为上舍函数
if(!isset($_GET['page']) || !intval($_GET['page']) || $_GET['page'] > $totalpages) $page = 1; //对3种出错进行默认处理
//在url参数page不存在时,page不为10进制数时,page大于可分页数时,默认为1
else $page = $_GET['page'];
$startnum = ($page - 1)*$maxnum; //从数据集第$startnum条开始取,注意数据集是从0开始的
echo $query = "SELECT * FROM Sheet1 Where Town like '%$search%' LIMIT $startnum,$maxnum";//选择出符合要求的数据 从$startnum条数据开始,选出$maxnum行
$result = mysql_query($query, $conn) or die(mysql_error());
$row = mysql_fetch_assoc($result);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=latin1_swedish_ci">
<title>Customers </title>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>
<style type="text/css">
a{text-decoration:none;}
a:hover{text-decoration:underline}
table{font-size:12px;}
.tb{background-color:#73BB95}
.tr{background-color:#FFFFFF}
</style>
</head>
<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" class="tb">
<tr>
<th height="24"> <div align="left">Company </div> </th>
<th height="24"> <div align="left">Salutation </div> </th>
<th height="24"> <div align="left">Forename </div> </th>
<th height="24"> <div align="left">Surname </div> </th>
<th height="24"> <div align="left">Job Title </div> </th>
<th height="24"> <div align="left">Address 1 </div> </th>
<th height="24"> <div align="left">Address 2 </div> </th>
<th height="24"> <div align="left">Address 3 </div> </th>
<th height="24"> <div align="left">Address 4 </div> </th>
<th height="24"> <div align="left">Town </div> </th>
<th height="24"> <div align="left">County </div> </th>
<th height="24"> <div align="left">Postcode </div> </th>
<th height="24"> <div align="left">Tel </div> </th>
<th height="24"> <div align="left">Email </div> </th>
<th height="24"> <div align="left">Thomson Classification </div> </th>
<th height="24"> <div align="left">SIC Code (UK 2007) </div> </th>
</tr>
<form method="GET" action="">Town <input name="Town" /> </form>
<?php if($totalRows1) {//记录集不为空显示
do {
?>
<tr class="tr">
<th height="24"> <div align="center"> <?php echo $row['Company'];?> </div> </th>
<th height="24"> <div align="center"> <?php echo $row['Salutation'];?> </div> </th>
<th height="24"> <div align="center"> <?php echo $row['Forename'];?> </div> </th>
<th height="24"> <div align="center"> <?php echo $row['Surname'];?> </div> </th>
<th height="24"> <div align="center"> <?php echo $row['Job Title'];?> </div> </th>
<th height="24"> <div align="center"> <?php echo $row['Address 1'];?> </div> </th>
<th height="24"> <div align="center"> <?php echo $row['Address 2'];?> </div> </th>
<th height="24"> <div align="center"> <?php echo $row['Address 3'];?> </div> </th>
<th height="24"> <div align="center"> <?php echo $row['Address 4'];?> </div> </th>
<th height="24"> <div align="center"> <?php echo $row['Town'];?> </div> </th>
<th height="24"> <div align="center"> <?php echo $row['County'];?> </div> </th>
<th height="24"> <div align="center"> <?php echo $row['Postcode'];?> </div> </th>
<th height="24"> <div align="center"> <?php echo $row['Telephone No'];?> </div> </th>
<th height="24"> <div align="center"> <?php echo $row['Email'];?> </div> </th>
<th height="24"> <div align="center"> <?php echo $row['Thomson Classification'];?> </div> </th>
<th height="24"> <div align="center"> <?php echo $row['SIC Code (UK 2007)'];?> </div> </th>
</tr>
<?php }while($row = mysql_fetch_assoc($result));?>
</table>
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr> <form name="form1">
<td height="27"> <div align="center">
<?php
echo "Total <font color=\"#ff0000\">$totalRows1 </font>";
echo " <font color=\"#ff0000\">".$page." </font>"."/".$totalpages."Pages";
//实现 < < < 1 2 3 4 5> >> 分页链接
$pre = $page - 1;//上一页
$next = $page + 1;//下一页
$maxpages = 4;//处理分页时 < < < 1 2 3 4 > >>显示4页
$pagepre = 1;//如果当前页面是4,还要显示前$pagepre页,如 < < < 3 /4/ 5 6 > >> 把第3页显示出来
if($page != 1) { echo " <a href='".$_SERVER['PHP_SELF']."?Town=$search'> < < </a> ";
echo " <a href='".$_SERVER['PHP_SELF'].'?page='.$pre."&Town=$search'> < </a> ";}
if($maxpages>=$totalpages) //如果总记录不足以显示4页
{$pgstart = 1;$pgend = $totalpages;}//就不所以的页面打印处理
elseif(($page-$pagepre-1+$maxpages)>$totalpages)//就好像总页数是6,当前是5,则要把之前的3 4 显示出来,而不仅仅是4
{$pgstart = $totalpages - $maxpages + 1;$pgend = $totalpages;}
else{
$pgstart=(($page <=$pagepre)?1:($page-$pagepre));//当前页面是1时,只会是1 2 3 4 > >>而不会是 0 1 2 3 > >>
$pgend=(($pgstart==1)?$maxpages:($pgstart+$maxpages-1));
}
$search = urlencode($search);
for($pg=$pgstart;$pg <=$pgend;$pg++){ //跳转菜单
if($pg == $page) echo " <a href=\"".$_SERVER['PHP_SELF']."?page=$pg&Town=$search\"> <font color=\"#ff0000\">$pg </font> </a> ";
else echo " <a href=\"".$_SERVER['PHP_SELF']."?page=$pg&Town=$search\">$pg </a> ";
}
if($page != $totalpages)
{echo " <a href='".$_SERVER['PHP_SELF'].'?page='.$next."&Town=$search'>> </a> ";
echo " <a href='".$_SERVER['PHP_SELF'].'?page='.$totalpages."&Town=$search'>>> </a> ";}
?>
<select name="menu1" onChange="MM_jumpMenu('parent',this,0)">
<option value="">Select </option>
<?php for($pg1=1;$pg1 <=$totalpages;$pg1++) {
echo " <option value=\"".$_SERVER['PHP_SELF']."?page=$pg1&Town=$search\">".$pg1." </option>";
}?>
</select>
</td> </form>
</tr>
</table>
<?php } else {//记录集为空时显示?>
<tr class="tr">
<td height="24"> <div align="center">No Result </div> </td>
</tr>
</table>
<?php }?>
</body>
</html>
<?php
mysql_free_result($result1);
mysql_free_result($result);
?> 

解决方案 »

  1.   

    你不懂php你老板为什么要叫你做这个??你这个问题是因为搜索关键词没有被传递到第二页。大概有3个地方要改:1)关键词通过GET获得
    2)form改为GET
    3)翻页的链接要加上这个关键词
      

  2.   

    给你一个我做的翻页功能的函数,稍做修改就能用了
    <?php
    $maxpage=10;
    $page=$_GET['page'];
    /***************************下面为用函数时的处理**************************************/
    function roll()
    {
    global $page,$maxpage;
    $o=$maxpage-4;
    if(empty($page) || $page<=6 || $maxpage<=9)
    $v=1;
    else if(($page<=$maxpage&&$page==$o)||($page<$maxpage&&$page>$o)||$page==$maxpage)
    $v=$maxpage-9;
    else
    $v=$page-5;
    for($i=$v;$i<=$v+9;$i++)
    {
    if($i==$page)
    echo "<a href=2.php?page=".$i."><font size='8'>".$i."</font></a> ";
    else
    echo "<a href=2.php?page=".$i.">".$i."</a> ";
    if($i==$maxpage)
    break;
    }
    }
    roll();
    ?>
    只要把你要搜索的条件加到echo "<a href=2.php?page=".$i.">".$i."</a> ";里面就可以了,致于你所说的问题正如1楼和2楼所说的去做就可以,有什么问题可以Q我,愿意帮忙。Q:75450644
      

  3.   

    问题已经解决了,但是好像老板还是不满意,又有了新的要求,能把已经处理的数据记录下来。
    我想到的办法是在每行之前都加一个checkbox,然后每处理一个数据就把已经处理的数据加时间戳保存在新的数据表中。
    大家觉得应该怎么做好呢?有人能帮忙么?不胜感激!