Advertisement
ruhul0

Pagination

May 7th, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.86 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <meta charset="utf-8">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1">
  6.     <link rel="stylesheet"
  7.     href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  8. </head>
  9. <body>
  10.     <div class="content"  align="center">
  11.   <form action="#" method="post">
  12.     <div class="input-group">
  13.       <input type="text" name="uid" placeholder="Enter Username">
  14.     </div>
  15.     <br>
  16.     <div class="input-group">
  17.       <button type="submit" class="btn" name="sprescription">Search Prescription</button>
  18.     </div>
  19.     <br>
  20.   </form>
  21.     <form action="dindex.php">
  22.     <div class="input-group">
  23.       <button type="submit" class="btn" name="back">Back</button>
  24.     </div>
  25.   </form>
  26. <?php
  27.     if(session_id() == ''){
  28.     //session has not started
  29.     session_start();
  30. }
  31.     $uid=$_POST['uid'];
  32.     $uid=(int)$uid;
  33.     //error_reporting(0);
  34.     // Import the file where we defined the connection to Database.
  35.     require_once "connection.php";
  36.  
  37.     $limit = 10; // Number of entries to show in a page.
  38.     // Look for a GET variable page if not found default is 1.   
  39.     if (isset($_GET["page"])) {
  40.     $pn = $_GET["page"];
  41.     }
  42.     else {
  43.     $pn=1;
  44.     };
  45.  
  46.     $start_from = ($pn-1) * $limit;
  47.  
  48.     $sql = "SELECT * FROM prescription WHERE pid='$uid' ORDER BY date DESC LIMIT $start_from, $limit";
  49.     $rs_result = mysqli_query ($conn,$sql);
  50.  
  51. ?>
  52. <div class="container">
  53.     <br>
  54.     <div>
  55.     <h1>Prescription</h1>
  56.     <table class="table table-striped table-condensed table-bordered">
  57.         <thead>
  58.         <tr>  
  59.         <th>Id</th>
  60.         <th>Medicine Name</th>
  61.         <th>Medicine Date</th>
  62.         <th>Doctor Id</th>
  63.         <th>Patient Id</th>
  64.         <th>Time</th>
  65.         <th>Timeline</th>
  66.         </tr>
  67.         </thead>
  68.         <tbody>
  69.         <?php
  70.         while ($row = mysqli_fetch_array($rs_result, MYSQLI_ASSOC)) {
  71.                 // Display each field of the records.
  72.         ?>
  73.         <tr>
  74.         <td><?php echo $row["id"]; ?></td>
  75.         <td><?php echo $row["mname"]; ?></td>
  76.         <td><?php echo $row["date"]; ?></td>
  77.         <td><?php echo $row["did"]; ?></td>
  78.         <td><?php echo $row["pid"]; ?></td>                                      
  79.         <td><?php echo $row["time"]; ?></td>
  80.         <td><?php echo $row["timeline"]; ?></td>       
  81.         </tr>
  82.         <?php
  83.         };
  84.         ?>
  85.         </tbody>
  86.     </table>
  87.     <ul class="pagination">
  88.     <?php
  89.         $sql = "SELECT COUNT(*) FROM prescription";
  90.         $rs_result = mysqli_query($conn,$sql);
  91.         $row = mysqli_fetch_row($rs_result);
  92.         $total_records = $row[0];
  93.        
  94.         // Number of pages required.
  95.         $total_pages = ceil($total_records / $limit);
  96.         $pagLink = "";                       
  97.         for ($i=1; $i<=$total_pages; $i++) {
  98.         if ($i==$pn) {
  99.             $pagLink .= "<li class='active'><a href='index.php?page="
  100.                                                 .$i."'>".$i."</a></li>";
  101.         }            
  102.         else {
  103.             $pagLink .= "<li><a href='index.php?page=".$i."'>
  104.                                                 ".$i."</a></li>";
  105.         }
  106.         };
  107.         echo $pagLink;
  108.     ?>
  109.     </ul>
  110.     </div>
  111. </div>
  112. </body>
  113. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement