I am using @Nev Stokes very elegant pagination script:
my version of the script is currently configured to scroll through each row of my sql table one row at a time using the prev/next buttons. I am trying to add in a drop down list that spits out all of the sql rows and clicking one of them advances the page to the correct page #.
The pagination component is working fine. For the drop down list however, I'm having trouble setting the href value for each list item.
After counting the number of sql rows, the pagination script defines the current page using the following:
// How many items to list per page
$limit = 1;
// How many pages will there be
$pages = ceil($total / $limit);
// What page are we currently on?
$page = min($pages, filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT, array(
'options' => array(
'default' => 1,
'min_range' => 1,
),
)));
It then adds 1 to $page for the next button, and subtracts 1 from $page for the previous button, and writes into the href for the button. ex)
<a href="?page='.($page + 1).'"title="Next page">
As for the drop down list I'm using:
//begin dropdown list
echo '<div class="dropdown" style="display:inline; margin-left:5%;">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-expanded="true">
Browse by address
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">';
//get all sql rows
$stmtdd = $conn->prepare('SELECT * FROM listings Order by id DESC');
$stmtdd->execute();
$stmtdd->setFetchMode(PDO::FETCH_ASSOC);
$iteratordd = new IteratorIterator($stmtdd);
foreach ($iteratordd as $row) {
$adrdd = $row['address'];
//print the address and link to the page
echo '<li role="presentation"><a role="menuitem" tabindex="-1" href="?page='.$currpagehref.'">'.$adrdd.'</a></li>';}
echo '</ul>
</div>';
How would I define $currpagehref (the href for the list item), it needs to ireterate the number in the sql row count essentially? Thank you in advance!