PHP Classes

File: test.php

Recommend this page to a friend!
  Classes of Wilson Fernandez   Mini Paginator   test.php   Download  
File: test.php
Role: Example script
Content type: text/plain
Description: test.php
Class: Mini Paginator
Show links to browse paginated listings
Author: By
Last change:
Date: 9 years ago
Size: 1,065 bytes
 

Contents

Class file image Download
<?php
// connection to the base //
$link = mysql_connect("localhost", "test", "password");
$db_selected = mysql_select_db("wilson_test", $link);

// first query //
$result1 = mysql_query("SELECT * FROM productos", $link);
$num_rows = mysql_num_rows($result1);

// required data //
$total_results = $num_rows; // total results from a query
$maximum_per_page = 3; // maximum results to show per page
$maximum_links = 5; // maximum links to show

// pagination process //
require_once("paginator/paginator.class.php");
$page = new Paginator();
$pagination = $page->paginate($total_results, $maximum_per_page, $maximum_links, "Light");

// second query //
$result2 = mysql_query("SELECT * FROM productos LIMIT $page->limit", $link);

// query results //
echo "<h1>Mini Paginator demo</h1>";
echo
"<table border='1' align='center'>";
while (
$row = mysql_fetch_array($result2))
{
    echo
"<tr><td>".$row['codigo']."</td><td>".$row['producto']."</td><td>".$row['precio']."</td></tr>";
}
echo
"</table>";

// paginator //
echo $pagination;
?>