Bookmarks PHP Pagination update

I have updated the view_bookmarks.php. script so that the pagination now works correctly once you have selected a category. This will of course only show once you have more than 10 records within a category as the $display is hard coded in at 10.

1) After the $display insert the below, this will check for a category id within the URL.


// check for category in URL
if (isset($_GET['cid']) && is_numeric($_GET['cid']) ) {
$cid = (int) $_GET['cid'];
}

2) Then after the // already determined.
if (isset($_GET[‘p’]) && is_numeric($_GET[‘p’])) {
$pages = $_GET[‘p’]; we need to include an else.


} else { // need to determine

if ($cid > 0) {

and a variable to check that the category id is greater than zero.

3) We need to write another mysql query to count the number of rows per category selected, then another else if no category is selected.


// Count number of records per category
$q = "SELECT COUNT(cat_id) FROM b_marks WHERE cat_id = $cid";
$r = @mysqli_query ($dbc, $q);
$row = @mysqli_fetch_array ($r, MYSQLI_NUM);
$records = $row[0];

} else {

4) Finally we need to edit the echo() statements that create the links so that the category value is passed. We add name=value ( ‘&cid=’ . $cid .) pair at the end of each statement. (PS: I had to remove some of the HTML from the below code for it to show, not sure why?)


// if it's not first page make a previous button:

if ($current_page !=1) {
href="view_bookmarks.php?s='. ($start - $display) . '&p=' . $pages '&cid=' . $cid . '">Previous;
}

// make all the numbered pages:

for ($i = 1; $i <= $pages; $i++) {
if ($i !=$current_page) {
echo ' herf="view_bookmarks.php?s='. (($display*($i - 1))). '&p=' . $pages .
'&cid=' . $cid . '">' .$i. ';
} else {
echo '<li>' .$i .'</li>';
}
} // end of FOR loop.

// If it's not the last page, make a Next button:
if ($current_page != $pages) {
echo'
href="view_bookmarks.php?s='. ($start + $display) . '&p=' . $pages .
'&cid=' . $cid . '">Next

I have a few more things in the pipeline to upgrade the bookmark app, so more coming soon ish!!!

Leave a Reply

Your email address will not be published. Required fields are marked *

To submit your comment, click the image below where it asks you to...
Clickcha - The One-Click Captcha