home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Master Visually: Macrome…a Dreamweaver 8 & Flash 8
/
MasterVisuallyDreamweaver8AndFlash8.iso
/
mac
/
Samples
/
ch16
/
display_page.php
< prev
next >
Wrap
PHP Script
|
2005-12-28
|
4KB
|
91 lines
<?php require_once('Connections/cxn_test2.php'); ?>
<?php
$currentPage = $_SERVER["PHP_SELF"];
$maxRows_age_list = 5;
$pageNum_age_list = 0;
if (isset($_GET['pageNum_age_list'])) {
$pageNum_age_list = $_GET['pageNum_age_list'];
}
$startRow_age_list = $pageNum_age_list * $maxRows_age_list;
mysql_select_db($database_cxn_test2, $cxn_test2);
$query_age_list = "SELECT last_name, age FROM customer ORDER BY last_name ASC";
$query_limit_age_list = sprintf("%s LIMIT %d, %d", $query_age_list, $startRow_age_list, $maxRows_age_list);
$age_list = mysql_query($query_limit_age_list, $cxn_test2) or die(mysql_error());
$row_age_list = mysql_fetch_assoc($age_list);
if (isset($_GET['totalRows_age_list'])) {
$totalRows_age_list = $_GET['totalRows_age_list'];
} else {
$all_age_list = mysql_query($query_age_list);
$totalRows_age_list = mysql_num_rows($all_age_list);
}
$totalPages_age_list = ceil($totalRows_age_list/$maxRows_age_list)-1;
$queryString_age_list = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_age_list") == false &&
stristr($param, "totalRows_age_list") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_age_list = "&" . htmlentities(implode("&", $newParams));
}
}
$queryString_age_list = sprintf("&totalRows_age_list=%d%s", $totalRows_age_list, $queryString_age_list);
?><!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>Display with paging</title>
</head>
<body>
<table border="1" align="center" cellpadding="5" cellspacing="5">
<tr>
<td align="center"><strong>last_name</strong></td>
<td align="center"><strong>age</strong></td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_age_list['last_name']; ?></td>
<td><?php echo $row_age_list['age']; ?></td>
</tr>
<?php } while ($row_age_list = mysql_fetch_assoc($age_list)); ?>
</table>
<p> </p>
<p>
<table border="0" width="50%" align="center">
<tr>
<td width="23%" align="center"><?php if ($pageNum_age_list > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_age_list=%d%s", $currentPage, 0, $queryString_age_list); ?>"><img src="Images/apache_pb.png" /></a>
<?php } // Show if not first page ?>
</td>
<td width="31%" align="center"><?php if ($pageNum_age_list > 0) { // Show if not first page ?>
<a href="<?php printf("%s?pageNum_age_list=%d%s", $currentPage, max(0, $pageNum_age_list - 1), $queryString_age_list); ?>"><img src="file:///C|/Program Files/Apache Group/Apache2/htdocs/apache_pb2.png" width="259" height="32" /></a>
<?php } // Show if not first page ?>
</td>
<td width="23%" align="center"><?php if ($pageNum_age_list < $totalPages_age_list) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_age_list=%d%s", $currentPage, min($totalPages_age_list, $pageNum_age_list + 1), $queryString_age_list); ?>">Next</a>
<?php } // Show if not last page ?>
</td>
<td width="23%" align="center"><?php if ($pageNum_age_list < $totalPages_age_list) { // Show if not last page ?>
<a href="<?php printf("%s?pageNum_age_list=%d%s", $currentPage, $totalPages_age_list, $queryString_age_list); ?>">Last</a>
<?php } // Show if not last page ?>
</td>
</tr>
</table>
</p>
<p>
Records <?php echo ($startRow_age_list + 1) ?> to <?php echo min($startRow_age_list + $maxRows_age_list, $totalRows_age_list) ?> of <?php echo $totalRows_age_list ?> </p>
</body>
</html>
<?php
mysql_free_result($age_list);
?>