I am trying to do pagination using javascript but all in vain, please help..
<script language="Javascript">
function nextclicked()
{
document.getElementById("clickednext").value = document.getElementById("clickednext").value + 1;
document.forms["newsmanager"].submit();
}
</script>
<form name = "newsmanager" method="post" action="NewsManager.php">
<input type = "hidden" id="clickednext" name="clickednext" >
if(isset($_POST['clickednext']) && $_POST['clickednext']>=1)
{
$_POST['clickednext'] = $_POST['clickednext'] +9;
$NewsQuery = "SELECT NewsDetails FROM News LIMIT " .$_POST['clickednext']. ",10";
}
else
{
$NewsQuery = "SELECT NewsDetails FROM News LIMIT 0,10";
}
$result = mysqli_query($dbc,$NewsQuery);
}
UPDATE :
<div class=d2 align=left>
<a href="#" onclick=" nextclicked(); submit();" >
Next
</a>
UPDATE ENDS……
The first time when i click the Next hyperlink label, then it works, that is, 10 is assigned $_POST[‘clickednext’] and the next 10 values appear from the database, but the second time i click the label , then it doesn’t?
Here’s a little algorithm I wrote using php to create pagination:
Where 5 is the number of stories per page, and
$numStoriesis the total amount of stories (or in your case, news articles) you wish to use.Then, just display the amount of pages (
$numPages) in any way you’d like, and your good to go.[EDIT]
I created an
archive.phppage, that took a page number as a GET parameter (archive.php?page=3). From there, I selected the first five entries in my database after$pageNum(in this case 3) *10(or however many posts per page you are wanting to display.The best thing to do is make as much of your code dynamic and flexible, so that it is self sustaining.
[EDIT 2]