Advertisement
Guest User

View - Pagination

a guest
Apr 26th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.62 KB | None | 0 0
  1. <?php
  2.    require_once('Database.php');
  3.    require_once('Paginator.php');
  4.  
  5.    $database = Database::getInstance();
  6.    $conn = $database->getConnection();
  7.  
  8.     $page = $_GET['page'] ?: 1;
  9.    
  10.     $paginator = new Paginator($conn);
  11.     $paginator->setQuery('SELECT * FROM users');
  12.     $result = $paginator->getResult($page);
  13. ?>
  14.  
  15. <!DOCTYPE html>
  16. <html lang="en">
  17. <head>
  18.     <meta charset="UTF-8">
  19.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  20.     <meta http-equiv="X-UA-Compatible" content="ie=edge">
  21.     <title>Document</title>
  22.     <style>
  23.         table {
  24.             border-collapse: collapse;
  25.         }
  26.  
  27.         table td,
  28.         table th {
  29.             border: 1px solid #ddd;
  30.             padding: 8px;
  31.         }
  32.     </style>
  33. </head>
  34. <body>
  35.     <table>
  36.         <thead>
  37.             <tr>
  38.                 <td>Name</td>
  39.                 <td>Username</td>
  40.                 <td>Email</td>
  41.             </tr>
  42.         </thead>
  43.         <tbody>
  44.             <?php foreach ($result->data as $row): ?>
  45.                     <tr>
  46.                         <td><?php echo $row->name; ?></td>
  47.                         <td><?php echo $row->username; ?></td>
  48.                         <td><?php echo $row->email; ?></td>
  49.                 </tr>
  50.             <?php endforeach; ?>
  51.         </tbody>
  52.     </table>
  53.     <br />
  54.     <?php echo $paginator->links(); ?>
  55.     <br />
  56.     <p>Current Page: <?php echo $result->page; ?></p>
  57.     <p>Limit: <?php echo $result->limit; ?></p>
  58.     <p>Total Items: <?php echo $result->total; ?></p>
  59.     <p>Total Pages: <?php echo $result->pages; ?></p>
  60. </body>
  61. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement