0
votes

I have 30 pages. sort by numbers ?page1 ?page2 ?page3......?page30

Assume Now, I stay on page=1 http://localhost/flowplayer/manga/manga_demo2.php?page=1

and If I want to add a button that link to next page (current page+1) How should I do?

This is my try but not work.

<input type="button" onclick="location.href='<?php echo $_SERVER['REQUEST_URI'] + 1;?>';" value="Next">
3
You can use $_GET['page'] to get the current value of the page number and plus it with one... Be sure to sanitize the string using either strip tags or htmlspecialchars. Google sanitizing GET phpuser2506641

3 Answers

0
votes
<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;

}
0
votes

I suppose this would do just fine. Explanation in comments:

<?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">
0
votes

you can really do it without any php code

<button id="b">click</button>
<script>
var pageStr=location.href.split("page=")[1];
var pageId=Number(pageStr);
b.onclick=function(){
    location.href="http://localhost/flowplayer/manga/manga_demo2.php?page="+ ++pageId;
}
</script>