我的代码如下
if(isset($_POST['find_x']) || isset($_POST['find_y'])){ ?>
<table style="font-family:Tahoma, Geneva, sans-serif; font-size:12px" width="100%" border="0" cellspacing="2" cellpadding="2">
<tr bgcolor="#FFFFFF" ><td colspan="11" align="left">Total Repairs: <? $count=mysql_num_rows($result); echo "<b style='color:#F00;'>".$count."</b>"; ?></td></tr>
<tr class="tableDetail" style="background-image:url(../images/tblHeaderBack.jpg);" >
<td align="center">Customer Name</td>
<td align="center">Serial #</td>
<td align="center">Ack No</td>
<td align="center">RAF Date</td>
<td align="center">Phone No</td>
<td align="center">Email</td>
<td align="center">Product Details</td>
<td align="center">Repair Status</td>
<td align="center">Location Name</td>
<td align="center">Physical Location</td>
<td align="center">Aging</td>
<td align="center">Assigned To</td>
<td align="center">Created By</td>
</tr>
<?
$adjacents = 1;
/*
First get total number of rows in data table.
If you have a WHERE clause in your query, make sure you mirror it here.
*/
$query = "select count(*) as num from tblRepairQueue where repairStatus!='Closed and Complete' ";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages[num];
/* Setup vars for query. */
$targetpage = "lookup1.php"; //your file name (the name of this file)
$limit =10; //how many items to show per page
$page = $_POST['page'];
if($page)
$start = ($page - 1) * $limit; //first item to display on this page
else
$start = 0; //if no page var is given, set start to 0
/* Get data. */
$sql = "select * from tblRepairQueue where repairStatus!='Closed and Complete' order by savedAt DESC LIMIT $start, $limit";
$result = mysql_query($sql);
/* Setup page vars for display. */
if ($page == 0) $page = 1; //if no page var is given, default to 1.
$prev = $page - 1; //previous page is page - 1
$next = $page + 1; //next page is page + 1
$lastpage = ceil($total_pages/$limit); //lastpage is = total pages / items per page, rounded up.
$lpm1 = $lastpage - 1; //last page minus 1
/*
Now we apply our rules and draw the pagination object.
We're actually saving the code to a variable in case we want to draw it more than once.
*/
$pagination = "";
if($lastpage > 1)
{
$pagination .= "<div class=\"pagination\">";
//previous button
if ($page > 1)
$pagination.= "<a href=\"$targetpage?page=$prev\">previous</a>";
else
$pagination.= "<span class=\"disabled\">previous</span>";
//pages
if ($lastpage < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
}
}
elseif($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some
{
//close to beginning; only hide later pages
if($page < 1 + ($adjacents * 2))
{
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
}
$pagination.= "...";
$pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
$pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";
}
//in middle; hide some front and some back
elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
{
$pagination.= "<a href=\"$targetpage?page=1\">1</a>";
$pagination.= "<a href=\"$targetpage?page=2\">2</a>";
$pagination.= "...";
for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
}
$pagination.= "...";
$pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
$pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";
}
//close to end; only hide early pages
else
{
$pagination.= "<a href=\"$targetpage?page=1\">1</a>";
$pagination.= "<a href=\"$targetpage?page=2\">2</a>";
$pagination.= "...";
for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
}
}
}
//next button
if ($page < $counter - 1)
$pagination.= "<a href=\"$targetpage?page=$next\">next </a>";
else
$pagination.= "<span class=\"disabled\">next </span>";
$pagination.= "</div>\n";
}
while($row = mysql_fetch_array($result))
{ ?>
<tr id="<?php $row['serialNo'] ?>" align="center" valign="top" style="background-color:#FFF">
<td ><?=$row['customerName']?></td>
<td ><?=$row['serialNo']?></td>
<td ><?=$row['ackNo']?></td>
<td ><?=$row['savedAt']?></td>
<td ><?=$details['phoneNo']?></td>
<td ><?=$details['emailId']?></td>
<td ><?=$row['productDescription']?></td>
<td nowrap="nowrap"><?=$row['repairStatus']?></td>
<td ><?=$row['location']?></td>
<td ><?=$row['phyLocation']?></td>
<td ><? echo "<b>".$days."</b><span style='color:#F00'>d</span> <b>".$hours."</b><span style='color:#F00'>hr</span> <b>".$mins."</b><span style='color:#F00'>m</span>";?></td>
<td ><?=$row['assignedTo']?></td>
<td ><?=$row['createdUser']?></td>
</tr>
<? } ?>
<tr>
<td align="center" colspan="9"><?=$pagination?> </td></tr>
</table>
<? }
?>
当我点击查找按钮时,分页仅出现在第一页,但如果我点击下一页或任何数字,它不工作。如果我点击下一步按钮,则无法正常工作..任何人都可以帮助我找到解决方案
答案 0 :(得分:1)
您正在检查POST方法变量:
if(isset($_POST['find_x']) || isset($_POST['find_y'])){ ?>
但您在分页中使用GET方法,因此后期变量不可用且该子句始终为false。
将搜索更改为使用$ _GET参数。所以在你的搜索表单中:
<form method="get" action="lookup1.php">
然后检查获取变量而不是post:
$find_x = (isset($_GET['find_x']) ? $_GET['find_x'] : '');
$find_y = (isset($_GET['find_y']) ? $_GET['find_y'] : '');
并将find_x和find_y添加到您的分页链接中,例如:
"<a href=\"$targetpage?page=$counter&find_x=$find_x\">$counter</a>"