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">
<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;
}
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">
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>