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
Easy to use – with just 4 simple steps.
Supports CSS – That means you have total control on the look and feel.
The code generated is 100% compliant with W3C XHTML standards.
Supports single table, custom SQL, Nested SQL, Joins, Union.
Built in support for English, and French languages.
Ability to easily add support for other languages.
Automatically includes existing query strings.
Supports multiple paging on same page!!!
Disadvantages / Known Issues
Current
development version support only MySQL database.
Future versions
are in pipeline to support all known databases.
Requirements
PHP 5
MySql 4 and above.
Apache / IIS
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:
Copy the two required files to the root folder and give a link to the style sheet and paging class.
Write PHP code to create an instance of paging class, and assign the table name to it.
Parse your custom SQL query to Paging class.
Display the paging information at required location.
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.
paging.class.php
paging.css
Give
link to the style sheet by putting the following code in between the
<head> tag of the page:
<link
type="text/css" href="paging.css"
rel="stylesheet" media="screen" />
Give
link to the paging class using the following code:
include_once("paging.class.php");
Create
an instance of the paging class as shown below:
$spPage
= new spa_paging;
Parse
your query through the pagingSql() method:
$sql =
"select * from comments";
$sql =
$spPage->pagingSql($sql);
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:
Specifying the page size: – i.e. Number of rows per page.
(Default English, and it even supports French)
Specify custom variable name instead of “spPage”.
Specifying a start page- Allows you to directly display a page of your choice.
Directly specify a table name instead of SQL script.
Specifying
the page size:
$pg2->pageSize = 4;
Specifying
the language:
$pg2->language
= “fr”; //to use French
Specifying
custom variable name instead of “spPage”.
$pg2->pageVar
= "page";
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
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
|
|
|
Developer: Prakash A Bhat (spabhat@yahoo.com, spabhat@gmail.com)
Skype id: spabhat