Ajax software
Free javascripts
↑
Main Page
// execute the query
$query_results = mysql_query($q);
// close database connection
DatabaseTools::closeConnection($db_link);
// return the results as an associative array
$rows = array();
while ($result = mysql_fetch_assoc($query_results)) {
$rows[] = $result;
}
return $rows;
}
}
?>
12.
Create a new file named
simple_pager.inc.php
in your
include
folder. Then write the
following code, which contains the
SimplePager
class. This class includes the functionality
to generate pager text and links:
<?php
// generates pager links
class SimplePager
{
var $_rows;
var $_limit;
var $_function_callback;
var $_page_number_parameter_index;
var $_max_listed_pages;
var $_previous_prompt;
var $_next_prompt;
var $_show_disabled_links;
// constructor
function SimplePager($rows, $limit, $function_callback,
$page_number_parameter_index = 1)
{
$this->_rows = $rows;
$this->_limit = $limit;
$this->_function_callback = $function_callback;
$this->_page_number_parameter_index = $page_number_parameter_index;
$this->_max_listed_pages = 10;
$this->_previous_prompt = ‘<< back’;
$this->_next_prompt = ‘next >>’;
}
// displays the pager links
function display($page_number = 1, &$rows, $additional_parameters = ‘’)
{
$offset = ($page_number - 1) * $this->_limit;
$row_count = sizeof($this->_rows);
$total_pages = ceil($row_count / $this->_limit);
$rows = array_slice($this->_rows, $offset, $this->_limit);
272
Chapter 14: Case Study: Building an E-Commerce Store
c14.qxd:c14 10:46 272
Ajax software
Free javascripts
→