我有一个正在处理的图库页面,似乎无法通过使用 GET 参数 page=2 正确加载下一组图像。
我正在使用一张带有 6 张图片以及下一个和上一个按钮的表格。但是,当我从第 1 页单击“下一步”时,它会加载图像 8 到 13,而不是商定的 7 到 12。
代码在这里:
<?php
echo "<table width=\"490\" border=\"1\" align=\"center\">";
if(isset($_GET['page'])){
//Read Page, Set Start image, End image
$cur_page=abs($_GET['page']);
//if the page is page1, then set the defaults
if($cur_page==1){
$prev_page=0;
$next_page=2;
$start_img=0;
$last_img=6;
}
//if the page is not page1, calculate the defaults
else{
$prev_page=$cur_page-1;
$next_page=$cur_page+1;
$start_img=(($cur_page-1)*6)+1;
$last_img=$start_img+5;
}
}else{
//Page=1 start image=1 end image=6
$cur_page=0;
$prev_page=1;
$next_page=2;
$start_img=0;
$last_img=6;
}
//Do the sql query for the images
$sql="SELECT * FROM images LIMIT $start_img, 6";
$result = mysql_query($sql, $conn) or die(mysql_error());
//Set a counter variable to iterate the image display
$count=0;
//Begin the table that displays the images.
while ($newArray = mysql_fetch_array($result)) {
$count++;
//Print the odd-numbered column first
if($count%2==1){
echo "<tr><td width=\"50%\"><a href=\"$newArray[Pic_Address]\">$newArray[Pic_Address]</a></td>";
//Print the even-numbered column next
}else{
echo "<td width=\"50%\"><a href=\"$newArray[Pic_Address]\">$newArray[Pic_Address]</a></td></tr>";
}
}
//print the next and previous Links
echo "<tr>";
if($prev_page==0){echo "<td align=\"center\">Prev</td>";}else{echo "<td align=\"center\"><a href=\"index.php?page=$prev_page\">Prev</a></td>";};
echo "<td align=\"center\"><a href=\"index.php?page=$next_page\">Next</a></td>";
echo "</tr>
</table>";
//Printscreen to test the page-load variables.
echo " <p align=\"center\">
current page=$cur_page <br>
prev_page=$prev_page <br>
next_page=$next_page <br>
start_img=$start_img <br>
last_img=$last_img <br>
</p>
";
?>