I have a php page that also has another php page inside it, this php page has a paginator, is it possible that every time i paginate it would only load the inside page not the whole page?
i tried to go around this by using AJAX as you can see to my first post but i encountered this problem where i need to fetch the letter and page that i sent to ajax and use it again for the pagination, so it would be like javascript sending its variable to php i tried this:
<script>
function pagereturn()
{
return getpage;
}
</script>
<?php
$pageno = pagereturn();
echo $pageno;
?>
function passPaginationAndLetter(page)
{
if (page=="")
{
document.getElementById("retail_group").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("retail_group").innerHTML=xmlhttp.responseText;
}
}
getpage = page;
xmlhttp.open("GET","otherpage.php? letter="+getletter+"&pageno="+page,true);
xmlhttp.send();
}
var page = 1;
$("#nextButton").click(function(){
page = page+1;
passPaginationAndLetter(page);
});
but unfortunately i ended up with no result and broke my code. btw getpage is a variable i took from another function.
Thank you very much, i am still new at javascript thus i am asking you for help. 🙂
—pagination code at child.php—-
{
}
else
{
if ($pageno == 1) {
//echo " FIRST PREV ";
}
else
{
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1'>FIRST</a> ";
$prevpage = $pageno-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>PREV</a> ";
}
echo " ( Page $pageno of $lastpage ) ";
if ($pageno == $lastpage)
{
//echo " NEXT LAST ";
}
else
{
$nextpage = $pageno+1;
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>NEXT</a> ";
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>LAST</a> ";
}
—pagination code at parent.php—–
else
{
echo '<a href = "#" onclick="passPaginationAndLetter("1"); return false;">FIRST</a>';
$prevpage = $pageno-1;
echo '<a href = "#" onclick="passPaginationAndLetter('.$prevpage.'); return false;">PREV</a>';
}
echo " ( Page $pageno of $lastpage ) ";
if ($pageno == $lastpage)
{
}
else
{
$nextpage = $pageno+1;
echo '<a id = "nextButton" href = "#" onclick="passPaginationAndLetter('.$nextpage.'); return false;">NEXT</a>';
echo '<a href = "#" onclick="passPaginationAndLetter('.$lastpage.'); return false;">LAST</a>';
}
ok, try this:
Let’s say you have your main page, the one who shows all the pagination, called main.php, also you have an other php file with all the functions called functions.php.
I assume that you have a php function in functions.php that genrates a single page of your pagination (
getAJAXpage($page)for example). This function generates a complete HTML page, something like this (REMEMBER this is just an example, could be implemented by 1000 different ways):what you can do in your php page main.php (the one who shows all the pagination) something like this:
I also assume that in your pagination page’s html in your main.php file you have at least a set of buttons (or icons) to direct the pagination (next, prev, first, last,…). So you can add this code to the above javascript.
and so with all the buttons.
NOTE: in this answer I also assume that you use the JQuery libray, highly recomended for begginers in javascript.
Hope I helped you. Good luck!