I have a query that currently looks like this:
$queryMovies = "SELECT
m.movieID,
n.title,
m.directorID, d.directorFirstName, d.directorLastName,
m.runTime,
m.yearReleased,
m.synopsis,
m.formatID, f.format,
FROM movies m
LEFT JOIN directors d ON d.directorID = m.directorID
LEFT JOIN format f ON f.formatID = m.formatID
ORDER BY title";
The results are sent back to the jQuery $.ajax call like so:
$arr = array();
while($row = mysqli_fetch_array($resultMovies, MYSQLI_ASSOC)) {
$arr[] = $row;
}
header('Content-Type: application/json');
echo json_encode($arr);
The success function of the $.ajax call handles the data something like this:
...
'<div class="synopsisCell">' +
'Synopsis<br />' +
'<label class="lblSynopsis">' + element['synopsis'] + '</label>' +
'</div>' +
'<div class="formatCell">' +
'<label class="lblFormat">' + element['format'] + '</label>' +
'</div>' +
'<div class="yearCell">' +
'<label class="lblYear">' + element['yearReleased'] + '</label>' +
'</div>' +
...
(As you can see that's an incomplete snippet of the full output)
I need to add pagination to the table that the data is being put into and I'm unsure of the best way to handle this. (I've never worked with programming for pagination before)
I started adding a separate query that just gets the number of records (to determine how many pages there will be), then I realized I still need to do a LIMIT clause with the start and number of records for the pagination, etc, etc.
I'm wondering two things at this point:
A) Could I in some way add the number of records to the existing query/return code, which I could then use on the jQuery side to build the pagination navigation (page number and next/prev/first/last page links).
or:
B) Could I maybe handle the pagination completely on the JS side by getting the number of records somehow from the JSON object and display only what set of results (which set of 20 records for example) to display in the table?
Also, when the user clicks on the pagination navigation links, will I have to re-run the query each time, or is there some way to "store" that info perhaps in the JS to avoid excessive server/database querying?
I'm not looking for specific coding, just maybe some pseudo-code to get me started in the right direction.
Thanks for anyone's help.