ADOdb Library for PHP Manual
Prev Implementing Scrolling with Next and Previous

Implementing Scrolling with Next and Previous

The following code creates a very simple recordset pager, where you can scroll from page to page of a recordset.


$db = NewADOConnection('mysql');
$sql = "select * from adoxyz ";

$pager = new ADODB_Pager($db,$sql);

This will create a basic record pager that looks like this:

|<   <<   >>   >|  

ID First Name Last Name Date Created
36  Alan  Turing  Sat 06, Oct 2001 
37  Serena  Williams  Sat 06, Oct 2001 
38  Yat Sun  Sun  Sat 06, Oct 2001 
39  Wai Hun  See  Sat 06, Oct 2001 
40  Steven  Oey  Sat 06, Oct 2001 

Page 8/10

The number of rows to display at one time is controled by the Render($rows) method. If you do not pass any value to Render(), ADODB_Pager will default to 10 records per page.

You can control the column titles by modifying your SQL (supported by most databases):

    $sql = 'select id as "ID", firstname as "First Name", lastname as "Last Name", created as "Date Created" from adoxyz';

The above code can be found in the adodb/tests/testpaging.php example included with this release, and the class ADODB_Pager in adodb/ The ADODB_Pager code can be adapted by a programmer so that the text links can be replaced by images, and the dull white background be replaced with more interesting colors.

You can also allow display of html by setting $pager->htmlSpecialChars = false.

Some of the code used here was contributed by Iván Oliva and Cornel G.

Prev Home Next
Generating Update and Insert SQL Up Exporting in CSV or Tab-Delimited Format

Sponsored by phpLens