0
$totalItemsRequired = 8;
$query = "SELECT * FROM fruits ORDER BY origin ASC ";
$result = mysqli_query($connection, $query);
if ($result == false)
{
echo "<p>Selecting all fruits failed.</p>";
}
else
{
$totalRecords = mysqli_num_rows($result);
$totalPages = ceil($totalRecords/$totalItemsRequired);
echo "<p>Page: ";
for ($i = 1; $i <= $totalPages; $i++)
{
echo "<a href='?page=" . $i . "'>" . $i . "</a> ";
}
echo "</p>";
if (isset($_GET['page']))
{
$currentPageNum = $_GET['page'];
$offset = ($currentPageNum - 1) * $totalItemsRequired;
$query = "SELECT * FROM fruits " . "LIMIT " . $offset . ", " . $totalItemsRequired;
$result = mysqli_query($connection, $query);
if ($result == false)
{
echo "<p>Selecting subset (page) of fruits failed.</p>";
}
else
{
echo "<ul>";
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
{
echo "<li>" . $row["id"] . "," . $row["name"] . ", " . $row["origin"] . ", " . $row["stock"] . "</li>";
}
echo "</ul>";
}
}
else
{
echo
// By default, load first page of records here
}
}
?>
嗨,我想在默認情況下,我已經把評論加載中記錄的第一頁。代碼沒有問題,初始輸出很好。我只是不知道如何顯示默認情況下。任何人都可以幫忙嗎?
編輯:任何人都可以幫忙嗎?
你能否在整個代碼中實現這一點,因爲我不確定你的意思? – bob123
@ bob123如果你沒有看到你的代碼的變化,那麼它可能不是你的代碼,因爲我已經在10秒內計算出它應用於哪個部分......並且我不是你的代碼的作者。 – KuKeC
@KuKeC我不明白你的意思 – bob123