SPA Simple Paging Class by spabhat - Version 2.0

SPA Simple Paging Class

License:

The SPA Simple Paging Class Ships with the

GNU GENERAL PUBLIC LICENSE

Version 3, 29 June 2007

With the help of SPA Simple Paging Class you can easily implement stylish paging on your site within 30 Seconds!!!.

Implementing the paging class is one of the easiest task, and it does not require too many customization. It just takes a table name, or a SQL script as input returns the number of pages. The paging class can be used on a single table or even with custom simple / complex SQL statements. ie. it now Supports JOINS, Nested SQL, UNION etc...




Advantages

  1. Easy to use – with just 4 simple steps.

  2. Supports CSS – That means you have total control on the look and feel.

  3. The code generated is 100% compliant with W3C XHTML standards.

  4. Supports single table, custom SQL, Nested SQL, Joins, Union.

  5. Built in support for English, and French languages.

  6. Ability to easily add support for other languages.

  7. Automatically includes existing query strings.

  8. Supports multiple paging on same page!!!

Disadvantages / Known Issues

  1. Current development version support only MySQL database.
    Future versions are in pipeline to support all known databases.


Requirements


Quick Usage code:

NOTE: Kindly refer to the “paging.php” file, which contains sample code for implementing the paging class using four different CSS styles.


<!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">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>SPA Paging Style</title>

<link type="text/css" href="paging.css" rel="stylesheet" media="screen" />

</head>

<body>

<p>Default Paging Style: </p>

<?php

include_once("paging.class.php"); // include the paging class


/* database connectivity */

mysql_connect("localhost","root",""); //you need to modify the connection settings

mysql_select_db("db_wikitime"); //you need to change the database name


$sql = "select * from comments"; //your custom sql statement


$spPage = new spa_paging; //create an instance of paging class

$sql = $spPage->pagingSql($sql); //parse the sql thru paging class


echo $spPage->getInfo(); //dispaly paging using the default style

?>

<h3>Implementing the paging with your SQL query:</h3>

<?php

//specify your SQL statement here, and append it with paging SQL


$resultRes = mysql_query($sql);

while($row = mysql_fetch_assoc($resultRes) )

{

echo ++$i . " ) " . $row['commentText'] . "<br />";

}

?>

</body>

</html>

Implementation steps in detail

Follow these 4 simple steps and display paging in 30 seconds:

  1. Copy the two required files to the root folder and give a link to the style sheet and paging class.

  2. Write PHP code to create an instance of paging class, and assign the table name to it.

  3. Parse your custom SQL query to Paging class.

  4. Display the paging information at required location.


  1. Copy the two required files to the root folder and give a link to the style sheet and paging class.

Copy the following two files to the root folder.

  1. Create an instance of the paging class as shown below:

    $spPage = new spa_paging;

  2. Parse your query through the pagingSql() method:

    $sql = "select * from comments";
    $sql = $spPage->pagingSql($sql);

  3. Locate the place where you would like to display the paging and write the following code

    echo $spPage->getInfo();

    // Now you just need to display the records on your page using the following code:

    $resultRes = mysql_query($sql);
    while($row = mysql_fetch_assoc($resultRes) )
    {
    echo ++$i . " ) " . $row['commentText'] ;
    echo
    "<br />";
    }

Customizing the paging class:

The paging class has various customization available, such as:


  1. Specifying the page size:
    $pg2->pageSize = 4;

  2. Specifying the language:
    $pg2->language = “fr”; //to use French

  3. Specifying custom variable name instead of “spPage”.
    $pg2->pageVar = "page";

  4. Specifying a start page:
    If you are using default setting you just need to add the following to the url:
    http://url?spPage=<required page number>
    ex:
    http://localhost/paging.php?spPage=4
    http://localhost/paging.php?spPage=10

    If you are using a custom variable name instead of spPage then:
    http://url?<custVarName>=<required page number>

    ex: (consider variable name is mpage)
    http://localhost/paging.php?mpage=4
    http://localhost/paging.php?mpage=10

  5. Directly specifying a table name instead of SQL script.

    $pg2 = new spa_paging; //create an instance of paging class with a different name

    $pg2->tableName = "comments"; //note the use of tale name instead of SQL query

    $sql = $pg2->pagingSql(); //get the required SQL from paging class
    echo $pg2->getInfo();

    $resultRes = mysql_query($sql); //executing the query


About me



Name:

Prakash A Bhat

Location:

Bangalore, India

Designation:

Software Developer

Software Skills:

Microsoft Technologies

ASP.NET, VB.NET, ASP, VB6


Web Developent Technologies

ASP, ASP.Net, PHP,

AJAX, JavaScript, VBScript,

HTML, DHTML,
Cascading Style Sheets (CSS)


XML based development

XML, XSL, XSLT


Others:

DOM, COM, DCOM, ActiveX


E-mail:

spabhat@yahoo.com / spabhat@gmail.com


Contact me for a complete PDF documentation.


You may support this open source software by donating.

Click on the Donate link below to donate me through Paypal.

Donate



Developer: Prakash A Bhat (spabhat@yahoo.com, spabhat@gmail.com)

Skype id: spabhat