This shows, you you may rape patTemplate to build a paginated list from any datasource by only using patTemplate. If you fully grasp how this works, you've mastered patTemplate :)
Output
PHP Source
Template source
Template Dump
<?PHP /** * patTemplate example that demonstrates how to build paginated * result sets from any database resultset. * * This is not very fast, but shows what patTemplate is capable * of, although it was never designed for this. * * $Id: example_realworld_paginate.php 453 2007-05-30 12:58:43Z gerd $ * * @author Stephan Schmidt <schst@php-tools.net> * @package patTemplate * @subpackage Examples * @link http://www.php-tools.net */
/** * Main examples prepend file, needed *only* for the examples framework! */ include_once 'patExampleGen/prepend.php';
// EXAMPLE START ------------------------------------------------------
/** * patErrorManager class */ require_once $neededFiles['patErrorManager'];
/** * set the number of entries on a page */ $entriesPerPage = 3;
/** * get the starting entries from the GET variables or set it * to zero by default */ $start = 0; if( isset( $_GET['start'] ) ) $start = $_GET['start'] - 1;
/** * template needs to know the script url */ $tmpl->addGlobalVar( 'script', $_SERVER['PHP_SELF'] );
/** * add the result set to the rows */ $tmpl->addRows( 'row', $rows ); /** * limit the rows */ $tmpl->setAttribute( 'row', 'limit', $start.','.$entriesPerPage );
/** * and here's the strange stuff: * * We add the result set to another template, which will generate the * links to all pages. The template is a modulo template, but contains * only one subtemplate. * * We define the number of different subtemplates by setting the modulo * attribute. If set to 3, there are three subtemplates: 1,2 and 3. As we * only define subtemplate '1', then only every third template is displayed. */ $tmpl->addRows( 'pages', $rows ); $tmpl->setAttribute( 'pages', 'modulo', $entriesPerPage );