This is the Title of the Book, eMatter Edition
Copyright © 2002 O’Reilly & Associates, Inc. All rights reserved.
Sample Application
|
211
Displaying the Database
Example 8-6 shows a page that displays the information in the database. The links
on the left side of the page are created from the
categories
table and link back to the
script, adding a category ID. The category ID forms the basis for a query on the
businesses
table and the
biz_categories
table.
// display
the submit button on new forms; link to a fresh registration
// page on confirmations
if ($add_record == 1){
echo '
Add
Another Business
';
} else {
echo '
';
}
?>
= $doc_title ?>
// establish the database connection
require_once('db_login.php');
$pick_message = 'Click on a category to find business listings:';
?>
Example 8-5. Adding a business (continued)
,ch08.16110 Page 211 Wednesday, March 13, 2002 11:44 AM
This is the Title of the Book, eMatter Edition
Copyright © 2002 O’Reilly & Associates, Inc. All rights reserved.
212
|
Chapter 8: Databases
= $pick_message ?> |
// build the scrolling pick list for the categories
$sql = "SELECT * FROM categories";
$result = $db->query($sql);
if (DB::isError($result)) die($result->getMessage( ));
while ($row = $result->fetchRow( )){
if (DB::isError($row)) die($row->getMessage( ));
echo '';
echo "";
echo "$row[1] | \n";
}
?>
|
if ($cat_id) {
$sql = "SELECT * FROM businesses b, biz_categories bc where";
$sql .= " category_id = '$cat_id'";
$sql .= " and b.business_id = bc.business_id";
$result = $db->query($sql);
if (DB::isError($result)) die($result->getMessage( ));
while ($row = $result->fetchRow( )){
if (DB::isError($row)) die($row->getMessage( ));
if ($color == 1) {
$bg_shade = 'dark';
$color = 0;
} else {
$bg_shade = 'light';
$color = 1;
}
echo "\n";
for($i = 0; $i < count($row); $i++) {
echo "$row[$i] | \n";
}
echo " \n";
}
}
?>
|
This page contains two images.
This page contains two images.
$im = imagecreatefromjpeg('php-tiny.jpg');
$dx = imagesx($im);
$dy = imagesy($im);
for($y = 0; $y < $dy; $y++) {
for($x=0; $x < $dx; $x++) {
$col = imagecolorat($im, $x, $y);
$rgb = imagecolorsforindex($im,$col);
printf('#',
$rgb['red'],$rgb['green'],$rgb['blue']);
}
echo "
\n";
}
imagedestroy($im);
?>
class BookList {
var $parser;
var $record;
var $current_field = '';
var $field_type;
var $ends_record;
var $records;
,ch11.16545 Page 275 Wednesday, March 13, 2002 11:45 AM