2017-03-11 16 views
0

ページの最初のページに関して、ページネーションは正常に機能しています。しかし、2番目以降のページでは機能しません。私は変数が適切に渡っていないと思う。私は名前「で「$名前 『変数を交換する場合』を問題はありません。任意のヒントは非常に理解されるであろう。私はそれを解決した2番目以降のページでページネーションが機能しない

**$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

改ページのURLを教えてNAME' '$何ですか –

+0

$名= $ _POST [ '名前? ']; – Ramen

+0

ページネーションURLには問題ありません – Ramen

答えて

0

。はい、それは$ _GETである[ 『名前』]。私はそれを変更し、今では正常に動作している

$名= $ _ GET [ '名前'];。

関連する問題