2017-03-11 92 views
0

關於初始頁面,我的分頁工作正常。但在第二頁及其後的頁面中,它不起作用。我認爲變量傳遞不正確。如果我「與$名爲」‘名稱替換變量’,那麼就沒有問題。任何提示將不勝感激。分頁不能在第二頁和後續頁面中工作

**$name = $_POST['name'];** 
    // how many rows to show per page 
$rowsPerPage = 5; 

// by default we show first page 
$page_num = 1; 

// if $_GET['page'] defined, use it as page number, $_GET gets the page number out of the url 
//set by the $page_pagination below 
if(isset($_GET['page'])){$page_num = $_GET['page'];} 

//the point to start for the limit query 
$offset = ($page_num - 1) * $rowsPerPage; 


// Zero is an incorrect page, so switch the zero with 1, mainly because it will cause an error with the SQL 
if($page_num == 0) {$page_num = 1;} 

// counting the offset 
$sql = "SELECT * FROM xyz WHERE name='$name' ORDER BY info_id ASC LIMIT $offset, $rowsPerPage "; 
$res = mysql_query($sql) or die(mysql_error()); 

// how many rows we have in database 
$sql2 = "SELECT COUNT(id) AS numrows FROM xyz WHERE name= '$name' "; 
$res2 = mysql_query($sql2) or die(mysql_error()); 
$row2 = mysql_fetch_array($res2); 
$numrows = $row2['numrows']; 

// print the random numbers 
while($row = mysql_fetch_array($res)) 
{ 
extract ($row); 
//Echo out your table contents here. 




echo "<tr class=\"alt\" onmouseover=\"ChangeColor(this, true);\" \n"; 
echo "style=\"cursor: pointer;\"\n"; 
echo " onmouseout=\"ChangeColor(this, false);\" \n"; 
echo " onclick=\"DoNav('http://www.example.com/searched_page.php?info_id={$info_id}');\">\n"; 
echo "\n"; 
$info_id = $row['info_id']; 


echo "</td>"; 
echo "<td>". $info_id . "</td>"; 
echo "<td>". $bname . "</td>"; 

echo "<td>". $text . "</td>"; 




echo "</tr>"; 
} 
?> 
<?php 
// how many pages we have when using paging? 
$maxPage = ceil($numrows/$rowsPerPage); 

$self = "http://www.example.com/search_category.php"; 

// creating 'previous' and 'next' link 
// plus 'first page' and 'last page' link 

// print 'previous' link only if we're not 
// on page one 
if ($page_num > 1) { 
    $page = $page_num - 1; 
    $prev = " <a href=\"$self?page=$page\">[Prev]</a> "; 

    $first = " <a href=\"$self?page=1\">[First Page]</a> "; 
} else { 
    $prev = ' [Prev] ';  // we're on page one, don't enable 'previous' link 
    $first = ' [First Page] '; // nor 'first page' link 
} 

// print 'next' link only if we're not 
// on the last page 
if ($page_num < $maxPage) { 
    $page = $page_num + 1; 
    $next = " <a href=\"$self?page=$page\">[Next]</a> "; 

    $last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> "; 
} else { 
    $next = ' [Next] ';  // we're on the last page, don't enable 'next' link 
    $last = ' [Last Page] '; // nor 'last page' link 
} 

// print the page navigation link 
//echo $first . $prev . " Showing page <strong>$page_num</strong> of  <strong>$maxPage</strong> pages " . $next . $last; 



?> 
</table> 

<table width="100%" border="0" cellspacing="0" cellpadding="0"> 
    <tr> 
     <td align="center" class="smaller"> 
      <?php 

      // print the page navigation link 
      echo '<br>'; 
      echo $first . $prev . " Page <strong>$page_num</strong> of <strong>$maxPage</strong>" . $next . $last; 

      ?> 
</table> 
+0

什麼是'$ name'是什麼分頁網址 –

+0

$名稱= $ _ POST ['的名字? ']; – Ramen

+0

在分頁URL中沒有問題 – Ramen

回答

0

我已經解決了。是的,這是$ _GET [‘名’]。我改變了它,現在它工作正常

$名稱= $ _ GET [ '名'];

相關問題