Server IP : 162.240.98.243 / Your IP : 3.137.163.36 Web Server : Apache System : Linux server.bti.yaw.mybluehostin.me 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64 User : btiyawmy ( 1003) PHP Version : 7.2.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/btiyawmy/public_html/login.easenup.in/ |
Upload File : |
<html> <head> <title>Pagination</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <style> table { border-collapse: collapse; } .inline{ display: inline-block; float: right; margin: 20px 0px; } input, button{ height: 34px; } .pagination { display: inline-block; } .pagination a { font-weight:bold; font-size:18px; color: black; float: left; padding: 8px 16px; text-decoration: none; border:1px solid black; } .pagination a.active { background-color: pink; } .pagination a:hover:not(.active) { background-color: skyblue; } </style> </head> <body> <center> <?php // Import the file where we defined the connection to Database. require_once "connection.php"; $per_page_record = 4; // Number of entries to show in a page. // Look for a GET variable page if not found default is 1. if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; } $start_from = ($page-1) * $per_page_record; $query = "SELECT * FROM admin LIMIT $start_from, $per_page_record"; $rs_result = mysqli_query ($conn, $query); ?> <div class="container"> <br> <div> <h1>Pagination Simple Example</h1> <p>This page demonstrates the basic Pagination using PHP and MySQL. </p> <table class="table table-striped table-condensed table-bordered"> <thead> <tr> <th width="10%">ID</th> <th>Name</th> <th>College</th> <th>Score</th> </tr> </thead> <tbody> <?php while ($row = mysqli_fetch_array($rs_result)) { // Display each field of the records. ?> <tr> <td><?php echo $row["hsname"]; ?></td> <td><?php echo $row["Name"]; ?></td> <td><?php echo $row["College"]; ?></td> <td><?php echo $row["Score"]; ?></td> </tr> <?php }; ?> </tbody> </table> <div class="pagination"> <?php $query = "SELECT COUNT(srno) FROM admin"; $rs_result = mysqli_query($conn, $query); $row = mysqli_fetch_row($rs_result); $total_records = $row[0]; echo "</br>"; // Number of pages required. $total_pages = ceil($total_records / $per_page_record); $pagLink = ""; if($page>=2){ echo "<a href='index1.php?page=".($page-1)."'> Prev </a>"; } for ($i=1; $i<=$total_pages; $i++) { if ($i == $page) { $pagLink .= "<a class = 'active' href='index1.php?page=" .$i."'>".$i." </a>"; } else { $pagLink .= "<a href='index1.php?page=".$i."'> ".$i." </a>"; } }; echo $pagLink; if($page<$total_pages){ echo "<a href='index1.php?page=".($page+1)."'> Next </a>"; } ?> </div> <div class="inline"> <input id="page" type="number" min="1" max="<?php echo $total_pages?>" placeholder="<?php echo $page."/".$total_pages; ?>" required> <button onClick="go2Page();">Go</button> </div> </div> </div> </center> <script> function go2Page() { var page = document.getElementById("page").value; page = ((page><?php echo $total_pages; ?>)?<?php echo $total_pages; ?>:((page<1)?1:page)); window.location.href = 'index1.php?page='+page; } </script> </body> </html>