Beginning PHP4 | 10 | WebReference

Beginning PHP4 | 10

current pageTo page 2To page 3To page 4

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>
   <FRAME NAME="sidebar" SRC="menu.html" FRAMEBORDER="No" BORDER=0 NORESIZE>

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

and menu.html, our sidebar:

<para>Enter an item to search for...</para>
<FORM NAME="search" ACTION="mall.php" TARGET="mall">
<INPUT TYPE="text" NAME="criteria" SIZE="20">
<INPUT TYPE="submit" VALUE="Search">

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:

include "./";
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:



current pageTo page 2To page 3To page 4

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