0

抱歉,我之前在 wordpress 上错误地提出了这个问题。我正在处理分页,但我面临一个问题,当我单击下一步时,它会增加下一页的查询字符串中的数字,但页面上的数据保持不变,我需要显示接下来的四条记录,因为我已经显示了每条记录页。代码看起来不错,但我不知道为什么它不起作用。下面是代码

$page = 0;

if($page == 0){

    $page = "1";

}else{

    // If page is set, let's get it
  echo   $page = $_GET['page'];

}

// Now lets get all messages from your database
$sql = "select * from about_us where sbmenu_id=9991";
$query = mysql_query($sql);

// Lets count all messages
$num = mysql_num_rows($query);

// Lets set how many messages we want to display
$per_page = "4";

// Now we must calculate the last page
$last_page = ceil($num/$per_page);

// And set the first page
$first_page = "1";

// Here we are making the "First page" link
echo "<a href='?page=".$first_page."'>First page</a> ";
echo $page ;
// If page is 1 then remove link from "Previous" word
if($page == $first_page){

    echo "Previous ";

  }else{

    if(!isset($page)){

            echo "Previous";

    }else{

            // But if page is set and it's not 1.. Lets add link to previous word to take us back by one page
            $previous = $page-1;
            echo "<a href='?page=".$previous."'>Previous</a> ";

    }

 }

 // If the page is last page.. lets remove "Next" link
 if($page == $last_page){

    echo "Next ";   

  }else{

    // If page is not set or it is set and it's not the last page.. lets add link to this word so we can go to the next page
    if(!isset($page)){

            $next = $first_page+1;
            echo "<a href='?page=".$next."'>Next</a> ";

    }else{

            $next = $page+1;
            echo "<a href='?page=".$next."'>Next</a> ";

    }

 }

 // And now lets add the "Last page" link
 echo "<a href='?page=".$last_page."'>Last page</a>";

 // Math.. It gets us the start number of message that will be displayed
 $start = ($page-1)*$per_page;

 // Now lets set the limit for our query
 $limit = "LIMIT $start, $per_page";

// It's time for getting our messages
$sql = "select * from about_us where sbmenu_id=9991 $limit";
$query = mysql_query($sql);
 ?><table><?php
echo "<br /><br /><tr style='height:70px;'>";

// And lets display our messages
while($row = mysql_fetch_array($query) or die(mysql_error()))
 {....}  
4

1 回答 1

1

更改前几行,然后尝试..

if(isset($_GET['page']) && $_GET['page'] > 0)        // If page is set, let's get it
{
    echo   $page = $_GET['page'];  
}
else
{
    $page = 1;
}

代替 : -

$page = 0;

if($page == 0){

$page = "1";

}else{

// If page is set, let's get it
 echo   $page = $_GET['page'];

}
于 2013-01-09T07:25:54.630 回答