Login   Register  
PHP Classes

File: index.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Michele Andreoli  >  Query paging  >  index.php  >  Download  
File: index.php
Role: Example script
Content type: text/plain
Description: Example of use
Class: Query paging
Show links to browse listings split in pages
Author: By
Last change: new table
Date: 4 years ago
Size: 2,884 bytes


Class file image Download
 * @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">
      <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>
      <h1>Paging Test</h1>
require_once 'Connection.class.php';

//Constructor for the database's connection
$db = new Connection("localhost""user""root""XXX");
//Open DB
//Query to split
$res $db->query("SELECT * FROM user WHERE 1 ORDER BY id");
          if (isset(
$page $_GET['page'];
$page 1;

           * Constructor for Paging class
           * @param GET value
           * @param number of rows
           * @param current page
           * @return instance of Paging class
$pag = new Paging($page5"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) {
"<table id=\"tableID\">";
"<thead class=\"headClass\">";
"</thead><tfoot class=\"footClass\">";
"</tfoot><tbody class=\bodyClass\">";
              foreach (
$result as $r) {
"<p>There aren't data</p>";

           * Show the navigation links
$pag->printLinks($db->getRows(), array("notSelected""selected""notSelected"));

//Close DB