Building A Framework - Page 11
January 12, 2001
Before we can start writing the actual scripts we need to create
a framework for them to work in. We are going to use a frameset
of two frames alongside one another. The left-hand frame is a
sidebar, while the right-hand frame will be where all of our
scripts run. Here is index.html:
<HEAD><TITLE>Our Interactive Mall</TITLE></HEAD>
<FRAMESET COLS="170,*">
<FRAME NAME="sidebar" SRC="menu.html"
FRAMEBORDER="No" BORDER=0 NORESIZE>
<FRAME NAME="mall" SRC="blank.html"
FRAMEBORDER="No" BORDER=0 NORESIZE>
</FRAMESET>
[Lines 3 and 4 above are one line as are lines 5 and 6. They
have been split for formatting purposes.]
To begin with, the right-hand frame will be blank, so here is
blank.html:
<html>
<body>
</body>
</html>
and menu.html, our sidebar:
<HTML>
<BODY>
Enter an item to search for...
<FORM NAME="search" ACTION="mall.php" TARGET="mall">
<INPUT TYPE="text" NAME="criteria" SIZE="20">
<BR>
<INPUT TYPE="submit" VALUE="Search">
</FORM>
</BODY>
</HTML>
Our form has an action of mall.php and a text box
called criteria. The target of the form is the
right-hand frame, in which we want our results displayed. Here's
the script that will do that job:
<?php
//mall.php
include "./common_db.inc";
if ($criteria!="") {
$link_id = db_connect('mapping');
$query = "SELECT m_name FROM mall WHERE m_desc LIKE
'%".$criteria."%'";
$mallResult = mysql_query($query, $link_id);
if (mysql_num_rows($mallResult) > 0) {
while ($mallRow = mysql_fetch_array($mallResult)) {
echo $mallRow[0]."<BR>";
}
}
}
?>
[Lines 6 and 7 above are one line. They have been split for
formatting purposes.]
Fire up the index.html file we created earlier,
enter shoes in the text box and click on
Submit. You should see the following results:
How It Works - Page 10
Beginning PHP4
Drawing the Layout - Page 12
|