Guest User

Untitled

a guest
Jul 4th, 2018
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.03 KB | None | 0 0
  1. <?php
  2.  
  3. $host = 'localhost';
  4. $dbname = 'test';
  5. $user = 'root';
  6. $pass = '';
  7.  
  8. try {
  9.     $DBH = new PDO("mysql: host=$host; dbname=$dbname", $user, $pass);
  10.     $DBH->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  11.    
  12.     $perPage = 6;
  13.     $pages = ceil(($DBH->query("SELECT COUNT(id) FROM xml")->fetchColumn()) / $perPage);
  14.     $offset = isset($_GET['page']) ? (int)(($_GET['page'] - 1) * $perPage) : 1;
  15.    
  16.     $STH = $DBH->query("SELECT * FROM xml LIMIT $offset, $perPage");
  17.     $STH->setFetchMode(PDO::FETCH_ASSOC);
  18.  
  19.     while($rows = $STH->fetch()) {
  20.         echo $rows['id'] . '<br />';
  21.         echo $rows['name'] . '<br />';
  22.     }
  23. }
  24. catch(PDOException $e) {
  25.     file_put_contents('PDOerror.txt', $e->getMessage(), FILE_APPEND);
  26. }
  27.  
  28. ?>
  29. <style type="text/css"> .active {font-weight: bold;} </style>
  30. <?php for ($p = 1; $p <= $pages; $p++): ?>
  31. <a <?php if (isset($_GET['page']) && $_GET['page'] == $p) echo 'class="active"'; elseif (!isset($_GET['page']) && $p == 1) echo 'class="active"';  ?> href="/?page=<?php echo $p; ?>"><?php echo $p; ?></a>
  32. <?php endfor; ?>
Add Comment
Please, Sign In to add comment