Home » Php » php – Pagination with Bootstrap and PDO

php – Pagination with Bootstrap and PDO

Posted by: admin February 25, 2020 Leave a comment

Questions:

How to create pagination with PDO PHP

I cant comment yet so i posted a new question:

My question is, if I use the “ANSWER” on that question with bootstrap, how do I put which button/link is active? 1
here is my code

<?php for ($page=1; $page <= $np ; $page++):?> 
<?php if ($_GET['p']==$page) { ?> 
<li class="page-item page-next"> 
<a href="<?php echo 'http://'.$_SERVER['SERVER_NAME'].'/inbox/'.$page.''; ?>" class="page-link"><?php echo $page; ?> </a> 
</li> 
<?php endfor; ?>
How to&Answers:

You can write an if condition in the for loop that show button/link, it will test if current iteration is same as $_GET value.

Workaround :

for ($page=1; $page <= $total_pages ; $page++):?>

<a href='<?php echo "?page=$page"; ?>' class="links <?php echo $_GET['page'] === $page ? 'active' : ''  ?>"><?php  echo $page; ?>
 </a>

<?php endfor; ?>