Showing the Shop Detail - Page 15
January 12, 2001
We're now going to develop the script
malldetail.php, which will display details of the
specific shop that the user clicked on. The first thing it has to
do is a database lookup for the shop information. It will then
display a thumbnail of the mall layout with just the current shop
highlighted.
In order to display a thumbnail of the image, we're going to use
a function called ImageCopyResized(). This lets us
copy a section of a source image, resize it, and paste it into a
new image. The function works with two images: a source image and
a destination image. It uses the following syntax:
ImageCopyResized(destination image,
source image,
destination x, destination y,
source x, source y,
destination width, destination height,
source width, source height);
For each image, we specify x and y coordinates, as well as a
width and a height. An area width wide and
height high, the top-left hand corner of which lives
at (x, y) is copied from the source image, scaled to
the correct width and height (as
specified for the destination image) and placed into the
destination image at the specified (x, y) position.
The diagram below illustrates the process:
Since showmall.php already has all the code we need
to display our mall, we'll just modify it to be able to display a
thumbnail of our image instead of the full thing.
Try It Out - Resizing Images
The first thing we need to do is to create our script
malldetail.php:
<?php
//malldetail.php
include "./common_db.inc";
$link_id = db_connect('mapping');
$query = "SELECT * FROM mall WHERE m_id=".$id;
$mallResult = mysql_query($query,$link_id) or die($query);
$mallRow = mysql_fetch_array($mallResult);
?>
<HTML>
<HEAD><TITLE><?php echo $mallRow[1]; ?></TITLE></HEAD>
<BODY>
<H3><?php echo $mallRow[3]; ?></H3>
<TABLE BORDER=0 WIDTH=500>
<TR>
<TD VALIGN="TOP" WIDTH=100>
<IMG SRC="showmall.php?show=<?php echo $mallRow[0]; ?>&
thumbnail=on" WIDTH=100 HEIGHT=100>
<TD VALIGN="TOP">
<TABLE BORDER=0 WIDTH=300>
<TR>
<TD><b>Shop Number:</b><br> <?php echo $mallRow[2]; ?></TD>
<TD><b>Phone Number:</b><br> <?php echo $mallRow[4]; ?></TD>
</TR>
<TR>
<TD COLSPAN=2><b>Keywords:</b><br>
<?php echo $mallRow[7]; ?>
</TD>
</TR>
</TABLE>
</TR>
</TABLE>
<A HREF="javascript:history.back()">Return</A>
</BODY>
</HTML>
Further Interactivity - Page 14
Beginning PHP4
Modifying the Script - Page 16
|