我試圖在搜索數據後進行分頁。在第一頁數據顯示,但如果點擊下一頁或頁碼沒有顯示。如果回到第一頁,那麼數據也會消失。請在這個問題上幫助我。搜索結果分頁不起作用
感謝
<FORM NAME="form1" METHOD="post" ACTION="">
<input type="text" name="university" value="" class="bgnone" >
<input name="search" value="search" class="bgnone" type="submit" ></SPAN>
</form>
<?php
include('connect.php');
$number=0;
if($_POST['search']){
$uni=$_POST['university'];
$per_page =10;
$page_num = 1;
if(isset($_GET['page'])){
if(is_numeric($_GET['page']))
$page_num = $_GET['page'];
}
$start = ($page_num-1)*$per_page;
$id=$_GET['id'];
$result = mysql_query("SELECT * FROM person where university = '$uni'");
/* $row_num = mysql_num_rows($result1);*/
$result_search= mysql_query(
"SELECT * FROM person where university = '$uni' order by id desc limit $start, $per_page");
$row_num = mysql_num_rows($result);
$max_pages = ceil($row_num/$per_page);
if(!$start){
$start = 0;
}
?>
<table>
<tr>
<td>Name </td>
<td>Email</td>
<td>Address</td>
<td>Phone</td>
</tr>
<?php
while($row_prev= mysql_fetch_array($result_search)){
?>
<TR>
<TD BGCOLOR="#FFFFCC" CLASS="n12" WIDTH=130><?php echo $row_prev['name'] ;?></TD>
<TD BGCOLOR="#99FF66" ROWSPAN="2" NOWRAP CLASS="n12"> <?php echo $row_prev['email'] ;?></TD>
<TD BGCOLOR="#99FF66" NOWRAP CLASS="n12"><?php echo $row_prev['address'] ;?></TD>
<TD BGCOLOR="#FFFFCC" CLASS="n12" WIDTH=140><?php echo $row_prev['phone'] ;?></TD>
</TR>
<?php } ?>
</table>
<?php
$previous = $page_num - 1;
$next = $page_num + 1;
?>
<div id="pagination">
<div id="firstpage">
<?php if($previous <= 0) { echo "<strong>First</strong>";}
else {echo "<a href='search.php?page=1'>First</a>";}
?>
</div>
<div id="previous">
<?php if($previous <= 0) { echo "<strong>Previous</strong>";}
else { echo "<a href='search.php?page=$previous'>Previous</a>"; }
?></div>
<div id="pagenumber" >
<?php
for($i=1; $i<=$max_pages; $i++)
{
echo "<a href='search.php?page=$i'>$i | </a>";
}
?>
</div>
<div id="next">
<?php
if($next > $max_pages) { echo "<strong>Next</strong>";}
else {echo "<a href='search.php?page=$next'>Next</a>";}
?></div>
<div id="last">
<?php
if($next > $max_pages){ echo "<strong>Last</strong>";}
else {echo "<a href='search.php?page=$max_pages'>Last</a>";}
?></div>
</div>
<?php } ?>
感謝您help.It工作。 – 2014-09-20 09:00:29