Good evening all,
Just after some pointers really on paginating json encoded data.
I have been looking at some other pages on stackoverflow and for some reason cannot seem to wrap my head around being able to paginate the returned json data.
I have had a look at the following pages: How to use jQuery to paginate JSON data?, PHP/JSON-jquery pagination and http://www.9lessons.info/2010/10/pagination-with-jquery-php-ajax-and.html
I have the following pages:
fia.php (database script)
<?php
include('constants.inc.php');
$result=mysql_query("SELECT id, firstname, lastname FROM ".PERSON." ORDER BY lastname ASC, firstname ASC LIMIT 0, 30");
$num=mysql_numrows($result);
$data = array();
while ($row = mysql_fetch_row($result))
{
$data[] = $row;
}
echo json_encode($data);
?>
fi.php (to display the results)
<?php
include('header.php');
?>
<script>
$(document).ready(function()
{
function loadit()
{
$.ajax(
{
url: "fia.php",
data: "",
dataType: "json",
success: function(d)
{
for (var i in d)
{
var r = d[i];
var id = r[0];
var fname = r[1];
var lname = r[2];
$('#stuff').append('<br/><b>ID</b> '+id+'<br/><b>Name</b> '+fname+' '+lname+'');
}
}
});
}
loadit();
});
</script>
<div id="stuff">Stuff goes here</div>
<?php
include('footer.php');
?>
I just can't seem to wrap my head around passing the page variables to the php script through the ajax call. Do I just pass the page variable through data? If so, how do I get the pagination to show under the returned results - just looking for some pointers as to how it could be done
If I use solely PHP, I can paginate it and range it just fine and it will switch pages as I move forwards or backwards
Thanks in advance (apologies if this question seems really dumb)