如何创建下一页的链接(当前页+ 1)

时间:2016-11-13 08:33:53

标签: javascript php html

我有30页。按数字排序?第1页?第2页?第3页......?第30页

现在假设,我留在页面= 1 http://localhost/flowplayer/manga/manga_demo2.php?page=1

如果我想添加链接到下一页的按钮(当前页+ 1)我该怎么办?

这是我的尝试,但不起作用。

<input type="button" onclick="location.href='<?php echo $_SERVER['REQUEST_URI'] + 1;?>';" value="Next">

3 个答案:

答案 0 :(得分:0)

<input type="button" onclick="location.href='<?php echo $_SERVER['REQUEST_URI'] + 1;?>';" value="Next">
instead of this you can do :
<input type="button" onClick="nextPage()"/>
function nextPage()
{
   var urlName=$_SERVER['REQUEST_URI'];
   var newUrlName=substr(urlName,0,urlName.length-6)."page=";
   var appendedValue=$_GET["page"]+1;
   location.href=newUrlName.appendedValue;

}

答案 1 :(得分:0)

我想这样做会很好。评论中的解释:

<?php

/* Get the full URL */
$url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

/* Get the page number */
$page = substr($url, -1);

/* Check if it's really a number for security */
if(!preg_match("/^[0-9]+$/", $page)){
    die("Invalid page number given!");
}

/* Remove the page number from the URL */
$url = rtrim($url, $page);

/* Count the page up with +1 */
$page++;

/* Generage the new url */
$newurl = $url . $page;

?>

<!-- Put it inside your button element -->

<input type="button" onclick="location.href='<?php echo $newurl; ?>';" value="Next">

答案 2 :(得分:0)

你可以在没有任何PHP代码的情况下真正做到这一点

hasNext()