Beginning PHP4 | 10 | WebReference

Beginning PHP4 | 10

current pageTo page 2To page 3To page 4
[next]

Beginning PHP4

Building a Framework

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>

To begin with, the right-hand frame will be blank, so here is blank.html:

and menu.html, our sidebar:

<HTML>
<BODY>
<para>Enter an item to search for...</para>
<FORM NAME="search" ACTION="mall.php" TARGET="mall">
<INPUT TYPE="text" NAME="criteria" SIZE="20">
<BR>
<INPUT TYPE="submit" VALUE="Search">
</INPUT></BR></INPUT></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>";
      }
   }
}
?>

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:

1

Contents

current pageTo page 2To page 3To page 4
[next]

and
Created: March 28, 2001
Revised: March 28, 2001

URL: http://webreference.com/programming/php/beginning/chap16/3/