Created
March 1, 2017 05:30
-
-
Save tanjilahmed7/b9289eedf54504b1fd31e01da18eb0cd to your computer and use it in GitHub Desktop.
Pagination
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function paginglink($query,$records_per_page) | |
| { | |
| $self = $_SERVER['PHP_SELF']; | |
| $stmt = $this->conn->prepare($query); | |
| $stmt->execute(); | |
| $total_no_of_records = $stmt->rowCount(); | |
| $total_no_of_pages = ceil($total_no_of_records / $records_per_page); | |
| if (!empty($_GET['page_no'])) { | |
| $page = $_GET['page_no']; | |
| $previous =$page-1; | |
| $next =$page+1; | |
| if ($page > 1) { | |
| ?> | |
| <style type="text/css"> | |
| li.pre{ | |
| display: block; | |
| } | |
| </style> | |
| <?php | |
| }else{ | |
| ?> | |
| <?php | |
| } | |
| } | |
| if (!empty($page)) { | |
| ?> | |
| <ul class="pager"> | |
| <li class='first'><a href='<?php echo $self; ?>'>First</a></li> | |
| <li class='pre'><a href='<?php echo $self."?page_no=".$previous; ?>'>Previous</a></li> | |
| <?php | |
| for($i = max(1, $page - 5); $i <= min($page + 5, $total_no_of_pages); $i++) | |
| { | |
| echo "<li class='link'><a href='".$self."?page_no=".$i."'>$i</a></li>"; | |
| } | |
| ?> | |
| <li><a href="<?php echo $self.'?page_no='.$next ?>">Next</a></li> | |
| </ul> | |
| <?php | |
| } | |
| else{ | |
| ?> | |
| <ul class="pager"> | |
| <li class='first'><a href='<?php echo $self; ?>'>First</a></li> | |
| <li><a href="<?php echo $self.'?page_no=1'?>">1</a></li> | |
| <li><a href="<?php echo $self.'?page_no=2'?>">2</a></li> | |
| <li><a href="<?php echo $self.'?page_no=3'?>">3</a></li> | |
| <li><a href="<?php echo $self.'?page_no=4'?>">4</a></li> | |
| <li><a href="<?php echo $self.'?page_no=5'?>">5</a></li> | |
| <li><a href="<?php echo $self.'?page_no=2' ?>">Next</a></li> | |
| </ul> | |
| <?php | |
| } | |
| ?> | |
| <?php | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (isset($_GET['page_no'])) { | |
| $page_id = $_GET['page_no']; | |
| $post_per_page = 50; | |
| $views = $page_id * $post_per_page; | |
| }else{ | |
| $post_per_page = 50; | |
| $views = 0; | |
| } | |
| <!-- Example --> | |
| $sql = "SELECT * FROM subscriptions WHERE magazine=2 ORDER BY subscription_id DESC LIMIT $views,$post_per_page"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment