<?php
/**
* @author Michele Andreoli <michi.andreoli@gmail.com>
* @name index.php
* @version 0.3
* @license http://opensource.org/licenses/gpl-license-php GNU Public License
* @package QueryPaging
*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="index.css" type="text/css" />
<title>Paging testing</title>
</head>
<body>
<h1>Paging Test</h1>
<br/>
<?php
require_once 'Connection.class.php';
require_once 'Paging.class.php';
//Constructor for the database's connection
$db = new Connection("localhost", "user", "root", "XXX");
//Open DB
$db->openDB();
//Query to split
$res = $db->query("SELECT * FROM user WHERE 1 ORDER BY id");
if (isset($_GET['page']))
$page = $_GET['page'];
else
$page = 1;
/**
* Constructor for Paging class
* @param GET value
* @param number of rows
* @param current page
* @return instance of Paging class
*/
$pag = new Paging($page, 5, "index.php");
/**
* Show the navigation links
* @param size of query result
* @param array with classes for css
* @return string to show
*/
$pag->printLinks(count($res), array("notSelected", "selected", "notSelected"));
/**
* Split the result in pages
* @param result of query
* @return array with the elements to show in page
*/
$result = $pag->rowsPerPage($res);
//Show the result in pages if result is greater than 0
if(count($result) > 0) {
echo "<table id=\"tableID\">";
echo "<thead class=\"headClass\">";
echo "<tr><td>Id</td><td>Name</td><td>E-Mail</td></tr>";
echo "</thead><tfoot class=\"footClass\">";
echo "<tr><td></td><td></td><td></td></tr>";
echo "</tfoot><tbody class=\bodyClass\">";
foreach ($result as $r) {
echo "<tr><td>$r[id]</td><td>$r[name]</td><td>$r[email]</td></tr>";
}
echo "</tbody>";
echo "</table>";
}
else
echo "<p>There aren't data</p>";
/**
* Show the navigation links
*/
$pag->printLinks($db->getRows(), array("notSelected", "selected", "notSelected"));
//Close DB
$db->closeDB();
?>
</body>
</html>
|