0

以前はこのコードを問題なく使用していましたが、どこが間違っていたかがわかれば、前/次のナビゲーションを押したときにページ要求を読み込めないようです。

<?php
include 'config.php';

$db = mysql_connect($host, $username, $password);
    mysql_select_db($db_name,$db);

        $sql = "SELECT u_id FROM users";
        $query = mysql_query($sql,$db);
        $total_results = mysql_num_rows($query);
        $limit = "5"; //limit of archived results per page.
        $total_pages = ceil($total_results / $limit); //total number of pages
if (empty($page))
    {
        $page = "1"; //default page if none is selected
    }
$offset = ($page - 1) * $limit; //starting number for displaying results out of DB

    $query = "SELECT * FROM users ORDER BY u_id LIMIT $offset, $limit";
    $result = mysql_query($query);
//This is the start of the normal results...

    while ($row = mysql_fetch_array($result))
        {
        ?>
<HR>
Username : <B><?echo $row['uname'] ?></B><BR>
user Message: <?echo $row['umess'] ?> 

<BR>


<?
        }
        mysql_close();

// This is the Previous/Next Navigation stuff having issue with

echo "<font face=Verdana size=1>";
echo "Pages:($total_pages)&nbsp;&nbsp;"; // total pages
if ($page != 1)
{
echo "<a href=?&page=1><< First</a>&nbsp;&nbsp;&nbsp;"; // First Page Link
$prevpage = $page - 1;
echo "&nbsp;<a href=?page=$prevpage><<</a>&nbsp;"; // Previous Page Link
}
        if ($page == $total_pages) 
            {
                $to = $total_pages;
            } 
        elseif ($page == $total_pages-1) 
            {
                $to = $page+1;
            } 
        elseif ($page == $total_pages-2) 
            {
                $to = $page+2;
            } 
        else 
            {
                $to = $page+3;
            }
        if ($page == 1 || $page == 2 || $page == 3) 
            {
                $from = 1;
            } 
        else 
            {
                $from = $page-3;
            }

for ($i = $from; $i <= $to; $i++)

    {
    if ($i == $total_results) $to=$total_results;
    if ($i != $page)
        {
        echo "<a href=?showold=yes&page=$i>$i</a>";
        }
    else
        {
        echo "<b><font face=Verdana size=2>[$i]</font></b>";
        }
    if ($i != $total_pages)
        echo "&nbsp;";
    }
if ($page != $total_pages)
{
$nextpage = $page + 1;
echo "&nbsp;<a href=?page=$nextpage>>></a>&nbsp;"; // Next Page Link
echo "&nbsp;&nbsp;&nbsp;<a href=?page=$total_pages>Last >></a>"; // Last Page Link
}
echo "</font>";



?>

テストの実行後、次のページまたはページ番号をクリックするまで、最初のページのリクエストが問題なく、最初のページに戻り続けることがわかります。

4

1 に答える 1

1

それ以外の

if (empty($page))
{
    $page = "1"; //default page if none is selected
}

試す :

if (isset($_GET['page']))
{
$page = $_GET['page'];
}
else
{
$page = 1;
}
于 2012-08-26T01:45:53.467 に答える