2015-04-05 39 views
-1

我正在研究一個Web搜索引擎項目。我正在研究分頁功能。當我點擊頁面時,它會給出突然的結果,並給出Undefined variable: page1 error。該怎麼辦?如何使用MySQL和PHP處理多個搜索結果的分頁問題?

if(isset($_GET['page'])) //results displayed based on page selection 
    { 
    $page=$_GET['page']; 
    if($page=="" || $page=="1") 
    { 
     $page1=0; 
    } 
    else 
    { 
    $page1=($page*10)-10; 
    } 
    } 

$numrows1 = mysqli_num_rows($query); // page evaluation and this statement calculates number of resultant rows 
$a = $numrows1/10; //10 is for number of results per page and $a gives number of pages 
$a = ceil($a); 
echo "<br>"; echo "<br>"; 
    for($b=1; $b<=$a; $b++) 
    { 
     ?><a href="search.php?page=<?php echo $b; ?>" style="text-decoration:none;"><?php echo $b." ";?></a><?php 
    } 

我希望我很清楚。任何人都可以幫我解決這個問題

回答

0

除非在URI中有頁面,否則您似乎從不設置頁面。

我假設如果您使用「page.php?page = 1」它不會拋出該錯誤,因爲$ page1將被設置。

我會親自做:

if(isset($_GET['page']) && $_GET['page'] != 1)//if page is set and page doesn't equal 1 
{ 
    $startingRecord = ($_GET['page'] * 10) - 10; 
} 
else 
{ 
    $startingRecord = 0; 
} 

而且,我切換$page1$startingRecord更有意義,因爲你正在計算的起始記錄,而不是頁面。

+0

謝謝你隊友! – sanjayacm 2015-04-07 18:48:22