Skip to main content
Sara_Reese
Inspiring
December 14, 2012
解決済み

Search / Results Page not showing results

  • December 14, 2012
  • 返信数 1.
  • 1040 ビュー

Hello, I am designing a "catalog" website for my work, which requires a "search products" element.

I have read that I need to do this "dynamically" in PHP and MySQL and so have been learning how to do this, and so far I have managed to:

1) set up WAMP

2) create "4 products (will eventually be 300 when I know it works)" sample database and have it "talk" to Dreamweaver (CS6)

3) Set up the "search form button"

4) create a search_results.php page with the dynamic table to hold the data / recordset

5) Get the correct results when I "test" the recordset as shown below: (i.e using "black" as the search test word which does correctly shows the one product out of the 4 that has black in the description column)


click on pic below to view:

6) it looks like it added it to the table correctly in design view in dreamweaver:

7) but when I preview it in the browser and type in "black" into the search box I dont get any results? I only get the titles of the columns? (image below of the results I get in the browser):

I've been looking on the internet / adobe help and have the "dummies" books and lynda.com dvds, but i've yet to find clear step by step instructions on how to do this properly - every source tends to miss out important steps and offers no solutions - according to lynda.com training dvd, it should now just work!. Does anyone know what I should be doing - I appear to be going around in circles with this one?  thanks.

PS I am a designer, and not a coder, and doing a dynamic site for the first time with no code knowledge, so please be gentle


このトピックへの返信は締め切られました。
解決に役立った回答 Sara_Reese

dont worry - i've figured it out.

返信数 1

Sara_Reese
Sara_Reese作成者
Inspiring
December 14, 2012

code below incase this helps:

<?php require_once('Connections/eternatest.php'); ?>

<?php

if (!function_exists("GetSQLValueString")) {

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

{

  if (PHP_VERSION < 6) {

    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {

    case "text":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;   

    case "long":

    case "int":

      $theValue = ($theValue != "") ? intval($theValue) : "NULL";

      break;

    case "double":

      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";

      break;

    case "date":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;

    case "defined":

      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

      break;

  }

  return $theValue;

}

}

$maxRows_Recordset1 = 10;

$pageNum_Recordset1 = 0;

if (isset($_GET['pageNum_Recordset1'])) {

  $pageNum_Recordset1 = $_GET['pageNum_Recordset1'];

}

$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

$colname_Recordset1 = "-1";

if (isset($_GET['description'])) {

  $colname_Recordset1 = $_GET['description'];

}

mysql_select_db($database_eternatest, $eternatest);

$query_Recordset1 = sprintf("SELECT * FROM productslist WHERE `description` LIKE %s ORDER BY code ASC", GetSQLValueString("%" . $colname_Recordset1 . "%", "text"));

$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);

$Recordset1 = mysql_query($query_limit_Recordset1, $eternatest) or die(mysql_error());

$row_Recordset1 = mysql_fetch_assoc($Recordset1);

if (isset($_GET['totalRows_Recordset1'])) {

  $totalRows_Recordset1 = $_GET['totalRows_Recordset1'];

} else {

  $all_Recordset1 = mysql_query($query_Recordset1);

  $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);

}

$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/maintemplate.dwt.php" codeOutsideHTMLIsLocked="false" -->

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<!-- InstanceBeginEditable name="doctitle" -->

<title>Eterna Lighting Ltd</title>

<!-- InstanceEndEditable -->

<style type="text/css">

.maincontainer {

          width: 850px;

          margin-right: auto;

          margin-left: auto;

}

.header {

          background-color: #333;

          height: 70px;

          width: 850px;

          font-family: Arial, Helvetica, sans-serif;

          font-size: 14px;

          color: #FFF;

          background-image: url(images/header_eterna.jpg);

}

.topnav {

          font-family: Arial, Helvetica, sans-serif;

          font-size: 14px;

          text-transform: uppercase;

          color: #FFF;

          background-color: #000;

          text-align: right;

          height: 20px;

          width: 850px;

          padding-top: 4px;

}

.leftnav {

          width: 180px;

          list-style-type: none;

          float: left;

          font-family: Arial, Helvetica, sans-serif;

          font-size: 14px;

          color: #000;

          background-color: #FFF;

          padding-top: 5px;

          padding-bottom: 5px;

}

.advert {

          font-family: Arial, Helvetica, sans-serif;

          font-size: 14px;

          height: 100px;

          width: 850px;

          margin-top: 5px;

}

.productarea {

          font-family: Arial, Helvetica, sans-serif;

          font-size: 14px;

          width: 660px;

          float: left;

          height: 800px;

          padding-left: 5px;

          padding-top: 5px;

          overflow: scroll;

          margin-top: 5px;

          margin-bottom: 5px;

          margin-left: 5px;

}

.footer {

          position: relative;

          clear: both;

          height: 50px;

          width: 850px;

          font-family: Arial, Helvetica, sans-serif;

          font-size: 14px;

          padding: 0px;

}

a:link {

          color: #333;

}

a:visited {

          color: #333;

}

a:hover {

          color: #999;

}

a:active {

          color: #999;

}

.maincontainer .topnav a:link {

          color: #FFF;

          text-decoration: underline;

}

.maincontainer .topnav a:visited {

          color: #FFF;

          text-decoration: underline;

}

.maincontainer .topnav a:hover {

          color: #999;

          text-decoration: underline;

}

.maincontainer .topnav a:active {

          color: #999;

          text-decoration: underline;

}

a img {

     border:none;

}

</style>

<script type="text/javascript">

function MM_preloadImages() { //v3.0

  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();

    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)

    if (a.indexOf("#")!=0){ d.MM_p=new Image; d.MM_p[j++].src=a;}}

}

function MM_swapImgRestore() { //v3.0

  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a)&&x.oSrc;i++) x.src=x.oSrc;

}

function MM_findObj(n, d) { //v4.01

  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {

    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

  if(!(x=d)&&d.all) x=d.all; for (i=0;!x&&i<d.forms.length;i++) x=d.forms;

  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers.document);

  if(!x && d.getElementById) x=d.getElementById(n); return x;

}

function MM_swapImage() { //v3.0

  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)

   if ((x=MM_findObj(a))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}

}

</script>

<meta name="keywords" content="Eterna, Lighting, Wellingborough, Northamptonshire, EBRITE, LED, Fluorescent, CFLi, Halogen, CFLni, Incandescent, Amenity, Bathroom, Cabinet, Ceiling & Wall, Display, Emergency, External Floodlighting, Garden & Sign, Lighting Controls, Recessed, Security, Transformers, Door Bells & Chimes, Electrical, Fire Safety, Hand Dryers, Heating" />

<meta name="description" content="Eterna Lighting are market leading importers and distributors of utility lighting products and electrical accessories, to electrical wholesale and OEM customers." />

<!-- InstanceBeginEditable name="head" -->

<!-- InstanceEndEditable -->

</head>

<body onload="MM_preloadImages('images/leftnavbtn_ebrite_cfliB.jpg','images/leftnavbtn_ebrite_cflniB.jpg','images/leftnavbtn_ebrite_halogenB.jpg','images/leftnavbtn_ebrite_incandB.jpg','images/leftnavbtn_ebrite_LEDB.jpg','images/leftnavbtn_amenityB.jpg','images/leftnavbtn_bathroomB.jpg','images/leftnavbtn_cabinetB.jpg','images/leftnavbtn_ceilingB.jpg','images/leftnavbtn_displayB.jpg','images/leftnavbtn_emergB.jpg','images/leftnavbtn_extfloodB.jpg','images/leftnavbtn_fluB.jpg','images/leftnavbtn_gardenB.jpg','images/leftnavbtn_LED_prodsB.jpg','images/leftnavbtn_lightingcontrolsB.jpg','images/leftnavbtn_recessedB.jpg','images/leftnavbtn_securityB.jpg','images/leftnavbtn_transformersB.jpg','images/leftnavbtn_newprodsB.jpg','images/leftnavbtn_doorB.jpg','images/leftnavbtn_elecB.jpg','images/leftnavbtn_fireB.jpg','images/leftnavbtn_handdryersB.jpg','images/leftnavbtn_heatingB.jpg')">

<div class="maincontainer">

  <div class="header">

    <table width="850" border="0" cellspacing="0" cellpadding="0">

      <tr>

        <td width="587" height="20"> </td>

        <td width="263"> </td>

      </tr>

      <tr>

        <td> </td>

        <td><form action="search_results.php" method="post" name="form1" target="_self" id="form1">

          <label for="search_box">Search</label>

          <input type="text" name="search_box" id="search_box" />

          <input type="submit" name="search_submit" id="search_submit" value="GO" />

        </form></td>

      </tr>

      <tr>

        <td> </td>

        <td> </td>

      </tr>

    </table>

  </div>

  <div class="topnav"><a href="index.php">home</a> | <a href="catalogue.php">catalogue</a> | <a href="about.php">ABOUT</a> | <a href="news.php">NEWS</a> | <a href="contact.php">CONTACT</a> | <a href="faq.php">faq</a> | <a href="tandcs.php">T&C'S</a>   </div>

  <div class="advert"><img src="images/advert.gif" width="850" height="100" alt="advert" /></div>

  <div class="leftnav">

    <table width="100%" border="0" cellspacing="0" cellpadding="0">

      <tr>

        <td><a href="index.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('New Products','','images/leftnavbtn_newprodsB.jpg',1)"><img src="images/leftnavbtn_newprods.jpg" alt="New Products" width="179" height="27" id="New Products" /></a></td>

      </tr>

      <tr>

        <td><a href="eternapro.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('EternaPro','','images/leftnavbtn_eternaproB.jpg',1)"><img src="images/leftnavbtn_eternapro.jpg" alt="EternaPro" width="179" height="27" id="EternaPro" /></a></td>

      </tr>

      <tr>

        <td><img src="images/leftnavbtn_ebritehead.jpg" width="179" height="27" alt="Ebrite" /></td>

     <tr>

        <td><a href="ebrite_led.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Ebrite LED','','images/leftnavbtn_ebrite_LEDB.jpg',1)"><img src="images/leftnavbtn_ebrite_LED.jpg" alt="Ebrite LED" width="179" height="27" id="Ebrite LED" /></a></td>

      </tr>

      <tr>

              <td><a href="ebrite_flu.php" target="_self" onmouseover="MM_swapImage('Ebrite Fluorescent','','images/leftnavbtn_ebrite_fluB.jpg',1)" onmouseout="MM_swapImgRestore()"><img src="images/leftnavbtn_ebrite_flu.jpg" alt="Ebrite Fluorescent" width="179" height="27" id="Ebrite Fluorescent" /></a></td>

      </tr>

      <tr>

        <td><a href="ebrite_cfli.php" target="_self" onmouseover="MM_swapImage('Ebrite CFLi','','images/leftnavbtn_ebrite_cfliB.jpg',1)" onmouseout="MM_swapImgRestore()"><img src="images/leftnavbtn_ebrite_cfli.jpg" alt="Ebrite CFLi" width="179" height="27" id="Ebrite CFLi" /></a></td>

      </tr>

      <tr>

              <td><a href="ebrite_halogen.php" target="_self" onmouseover="MM_swapImage('Ebrite Halogen','','images/leftnavbtn_ebrite_halogenB.jpg',1)" onmouseout="MM_swapImgRestore()"><img src="images/leftnavbtn_ebrite_halogen.jpg" alt="Ebrite Halogen" width="179" height="27" id="Ebrite Halogen" /></a></td>

      </tr>

      <tr>

        <td><a href="ebrite_cflni.php" target="_self" onmouseover="MM_swapImage('Ebrite CFLni','','images/leftnavbtn_ebrite_cflniB.jpg',1)" onmouseout="MM_swapImgRestore()"><img src="images/leftnavbtn_ebrite_cflni.jpg" alt="Ebrite CFLni" width="179" height="27" id="Ebrite CFLni" /></a></td>

      </tr>

      <tr>

        <td><a href="ebrite_incandescent.php" target="_self" onmouseover="MM_swapImage('Ebrite Incandescent','','images/leftnavbtn_ebrite_incandB.jpg',1)" onmouseout="MM_swapImgRestore()"><img src="images/leftnavbtn_ebrite_incand.jpg" alt="Ebrite Incandescent" width="179" height="27" id="Ebrite Incandescent" /></a></td>

      </tr>

      <tr>

        <td><img src="images/leftnavbtn_lightingHEAD.jpg" width="179" height="27" alt="Lighting Range" /></td>

      </tr>

      <tr>

        <td><a href="amenity.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Amenity','','images/leftnavbtn_amenityB.jpg',1)"><img src="images/leftnavbtn_amenity.jpg" alt="Amenity" width="179" height="27" id="Amenity" /></a></td>

      </tr>

      <tr>

        <td><a href="bathroom.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Bathroom','','images/leftnavbtn_bathroomB.jpg',1)"><img src="images/leftnavbtn_bathroom.jpg" alt="Bathroom" width="179" height="27" id="Bathroom" /></a></td>

      </tr>

      <tr>

        <td><a href="cabinet.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Cabinet','','images/leftnavbtn_cabinetB.jpg',1)"><img src="images/leftnavbtn_cabinet.jpg" alt="Cabinet" width="179" height="27" id="Cabinet" /></a></td>

      </tr>

      <tr>

        <td><a href="ceiling_wall.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Ceiling & Wall','','../images/leftnavbtn_ceilingB.jpg',1)"><img src="images/leftnavbtn_ceiling.jpg" alt="Ceiling & Wall" width="179" height="27" id="Ceiling & Wall" /></a></td>

      </tr>

      <tr>

        <td><a href="display.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Display','','images/leftnavbtn_displayB.jpg',1)"><img src="images/leftnavbtn_display.jpg" alt="Display" width="179" height="27" id="Display" /></a></td>

      </tr>

      <tr>

        <td><a href="emergency.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Emergency','','images/leftnavbtn_emergB.jpg',1)"><img src="images/leftnavbtn_emerg.jpg" alt="Emergency" width="179" height="27" id="Emergency" /></a></td>

      </tr>

      <tr>

        <td><a href="external_flood.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('External Floodlight','','images/leftnavbtn_extfloodB.jpg',1)"><img src="images/leftnavbtn_extflood.jpg" alt="External Floodlighting" width="179" height="27" id="External Floodlight" /></a></td>

      </tr>

      <tr>

        <td><a href="fluorescent.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Fluorescent','','images/leftnavbtn_fluB.jpg',1)"><img src="images/leftnavbtn_flu.jpg" alt="Fluorescent" width="179" height="27" id="Fluorescent" /></a></td>

      </tr>

      <tr>

        <td><a href="garden_sign.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Garden & Sign','','../images/leftnavbtn_gardenB.jpg',1)"><img src="images/leftnavbtn_garden.jpg" alt="Garden & Sign" width="179" height="27" id="Garden & Sign" /></a></td>

      </tr>

      <tr>

        <td><a href="led_products.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('LED Products','','images/leftnavbtn_LED_prodsB.jpg',1)"><img src="images/leftnavbtn_LED_prods.jpg" alt="LED Products" width="179" height="27" id="LED Products" /></a></td>

      </tr>

      <tr>

        <td><a href="lighting_controls.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Lighting Controls','','images/leftnavbtn_lightingcontrolsB.jpg',1)"><img src="images/leftnavbtn_lightingcontrols.jpg" alt="Lighting Controls" width="179" height="27" id="Lighting Controls" /></a></td>

      </tr>

      <tr>

        <td><a href="recessed.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Recessed','','images/leftnavbtn_recessedB.jpg',1)"><img src="images/leftnavbtn_recessed.jpg" alt="Recessed" width="179" height="27" id="Recessed" /></a></td>

      </tr>

      <tr>

        <td><a href="security.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Security','','images/leftnavbtn_securityB.jpg',1)"><img src="images/leftnavbtn_security.jpg" alt="Security" width="179" height="27" id="Security" /></a></td>

      </tr>

      <tr>

        <td><a href="transformers.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Transformers','','images/leftnavbtn_transformersB.jpg',1)"><img src="images/leftnavbtn_transformers.jpg" alt="Transformers" width="179" height="27" id="Transformers" /></a></td>

      </tr>

      <tr>

        <td><img src="images/leftnavbtn_NONlightingHEAD.jpg" width="179" height="27" alt="Non Lighting Range" /></td>

      </tr>

      <tr>

        <td><a href="doorbells_chimes.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Doorbells & Chimes','','../images/leftnavbtn_doorB.jpg',1)"><img src="images/leftnavbtn_door.jpg" alt="Doorbells & Chimes" width="179" height="27" id="Doorbells & Chimes" /></a></td>

      </tr>

      <tr>

        <td><a href="electrical_accessories.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Electrical Accessories','','images/leftnavbtn_elecB.jpg',1)"><img src="images/leftnavbtn_elec.jpg" alt="Electrical Accessories" width="179" height="27" id="Electrical Accessories" /></a></td>

      </tr>

      <tr>

        <td><a href="firesafety.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Fire Safety','','images/leftnavbtn_fireB.jpg',1)"><img src="images/leftnavbtn_fire.jpg" alt="Fire Safety" width="179" height="27" id="Fire Safety" /></a></td>

      </tr>

      <tr>

        <td><a href="hand_dryers.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Hand Dryers','','images/leftnavbtn_handdryersB.jpg',1)"><img src="images/leftnavbtn_handdryers.jpg" alt="Hand Dryers" width="179" height="27" id="Hand Dryers" /></a></td>

      </tr>

      <tr>

        <td><a href="heating.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Heating','','images/leftnavbtn_heatingB.jpg',1)"><img src="images/leftnavbtn_heating.jpg" alt="Heating" width="179" height="27" id="Heating" /></a></td>

      </tr>

    </table>

  </div>

  <!-- InstanceBeginEditable name="main" -->

  <div class="productarea">

    <table width="613" height="138">

      <tr>

        <td>code</td>

        <td>description</td>

        <td>link</td>

      </tr>

      <?php do { ?>

      <tr>

        <td><?php echo strtoupper($row_Recordset1['code']); ?></td>

        <td><?php echo strtoupper($row_Recordset1['description']); ?></td>

        <td><?php echo $row_Recordset1['link']; ?></td>

      </tr>

      <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>

    </table>

  </div>

  <!-- InstanceEndEditable -->

  <div class="footer"><img src="images/footer.jpg" width="850" height="50" alt="footer - copyright at Eterna Lighting Ltd - Registered in UK No. 410716" /></div>

</div>

</body>

<!-- InstanceEnd --></html>

<?php

mysql_free_result($Recordset1);

?>

Sara_Reese
Sara_Reese作成者解決!
Inspiring
December 14, 2012

dont worry - i've figured it out.