好的,所以我得到了这个代码,它假设从我的数据库中带回我的所有结果并每页显示 5 个结果。目前我的数据库中有 12 个结果,它只显示 10 个,它不会显示第 3 页,因为没有 5 个结果要显示。这是我的代码
//$_GET['page'] is to get the current page opened
if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; };
$results_per_page = "5"; //number of results I want displayed per page
$start_from = ($page-1) * $results_per_page;
$query = "SELECT * FROM items WHERE subcat = '$conditions' LIMIT $start_from, $results_per_page";
$result = mysql_query($query) or die("Unable to verify user because : " . mysql_error());
while ($row_condition=mysql_fetch_array($result)) {
//Display the results here
}
//Count number of results from database and work out how
//many pages I need to display all the results.
$result1 = mysql_query("SELECT * FROM items WHERE subcat = '$conditions'");
$num_rows = mysql_num_rows($result1);
$num_pages = $num_rows / $results_per_page;
if ($num_rows > $results_per_page){
?>
<div id="pagenum">
<?php
//This creates and displays the page numbers for the user to select
foreach( range( 1, $num_pages) as $i) {
if ($thepage == $i){
echo '<b><a href="browse.php?condition=' . $condition . '&page=' . $i . '">' . $i . '</a></b>';
}else{
echo '<a href="browse.php?condition=' . $condition . '&page=' . $i . '">' . $i . '</a>';
}
//This places a line between each number of pages
if ($i == $num_pages){
}else{
echo " | ";
}
}
?>
</div>
<?php
}else{ echo "Test";}
?>
那么任何人都可以看到这个问题吗?所以我的数据库中有 12 个条目。但是我只得到 2 页,每页 5 页,而我没有得到第 3 页,因为只剩下 2 个结果,而且似乎需要 5 个来完成它。谢谢