我已经构建了一个php脚本来反复导航我的博客页面,但是第一页显示正确,但是当我导航到下一页时它会显示正确的数字,但仍然显示相同的内容之前。然后,下一个按钮会一直显示当前页面。
这是我的剧本:
$publication = "magazine";
$ppp = "6";
if(isset($_GET["id"])){$id = $_GET["id"];}else{
header("Location: ".$url."");
exit();
}
if(isset($_GET["currentpage"])){$currentpage = $_GET["currentpage"];}else{
header("Location: ".$url."");
exit();
}
$count_sql = "SELECT id FROM publication_posts WHERE publication = '".$publication."' AND issue = '".$id."'";
$count_res = mysqli_query($con, $count_sql);
$count_total = mysqli_num_rows($count_res);
//If None, Then Exit
if($count_total == 0){
header("Location: ".$url."");
exit();
}
$display_limit = $ppp;
$totalpages = ceil($count_total / $display_limit);//$rowsperpage
$currentpage = $totalpages;
$offset = ($totalpages - 1) * $display_limit;//$rowsperpage
if($currentpage == "0"){
header("Location: ".$url."/issue/".$id."/".$totalpages."");
exit();
}
$posts_sql = "SELECT * FROM publication_posts WHERE publication = '".$publication."' AND issue = '".$id."' ORDER BY id DESC LIMIT ".$offset.", ".$display_limit."";
我在此注意到的另一件事是,如果我将当前页面设置为0
,它仍会显示issue/id/0
,而这应该重定向到$totalpages
任何人都知道问题在哪里?
这是我的分页:
<?php
// range of num links to show
$range = 0;
if ($currentpage != $totalpages) {
// get next page
$nextpage = $currentpage + 1;
// echo forward link for next page
$link_next = "<a href=\"issue/".$id."/".$nextpage."\"><div class=\"pagiCell pagiNext fadeOut\"></div></a>";
}
else{
$link_next = "<div class=\"pagiCell pagiNextX\"></div>";
}
?>
<?php
// range of num links to show
$range = 0;
if ($currentpage > 1) {
// get previous page
$prevpage = $currentpage - 1;
// echo forward link for next page
$link_prev = "<a href=\"issue/".$id."/".$prevpage."\"><div class=\"pagiCell pagiPrev fadeOut\"></div></a>";
}
else{
$link_prev = "<div class=\"pagiCell pagiPrevX\"></div>";
}
?>
<?php
$link_refresh = "<a href=\"issue/".$id."/1\"><div class=\"pagiCell pagiRefresh fadeOut\"></div></a>";
?>
<?php
$randpage = rand(1,$totalpages);
$link_random = "<a href=\"issue/".$id."/".$randpage."\"><div class=\"pagiCell pagiRandom fadeOut\"></div></a>";
?>
短网址:localhost/publication/magazine/issue/1/1
长网址:localhost/publication/magazine/issue?id=1¤tpage=1
答案 0 :(得分:0)
我认为您的问题是您的$currentpage
var是一个字符串,而您正在使用它进行数学运算而不进行转换。你应该输入cast it:PHP: Type Juggling
$nextpage = $currentpage + 1;
变为$nextpage = (int)$currentpage + 1;
就像Magnus Eriksson之前所说的那样,您没有检查用户输入是否存在安全问题。测试变量的预期值意味着,例如PHP: is_int