Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $host = 'localhost';
- $dbname = 'test';
- $user = 'root';
- $pass = '';
- try {
- $DBH = new PDO("mysql: host=$host; dbname=$dbname", $user, $pass);
- $DBH->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $perPage = 6;
- $pages = ceil(($DBH->query("SELECT COUNT(id) FROM xml")->fetchColumn()) / $perPage);
- $offset = isset($_GET['page']) ? (int)(($_GET['page'] - 1) * $perPage) : 1;
- $STH = $DBH->query("SELECT * FROM xml LIMIT $offset, $perPage");
- $STH->setFetchMode(PDO::FETCH_ASSOC);
- while($rows = $STH->fetch()) {
- echo $rows['id'] . '<br />';
- echo $rows['name'] . '<br />';
- }
- }
- catch(PDOException $e) {
- file_put_contents('PDOerror.txt', $e->getMessage(), FILE_APPEND);
- }
- ?>
- <style type="text/css"> .active {font-weight: bold;} </style>
- <?php for ($p = 1; $p <= $pages; $p++): ?>
- <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>
- <?php endfor; ?>
Add Comment
Please, Sign In to add comment