i wrote a search page for my site (searching through a mysql database) but
when i type in more than one word (eg "item three") in the search field it
gets passed to the page as a single word ("item"). Are there any
workarounds for this? the code is below.( houseproudlancs.co.uk/search.php
)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<!-- background="./images/background.jpg" --> <body bgcolor="#640000">
<?php
$search_for = $_GET['for'];
$search_category = $_GET['category']; global $search_for;
global $search_category;
global $the_items_description;
global $does_contain_text;
?>
<div align=center>
<form action="http://www.houseproudlancs.co.uk/search.php"
method="GET"> <br><table bgcolor="#EBEB96" cellpadding=6>
<tr> <td> </td> </tr> <tr> <td> <div align=center> Search For:
</div></td> <td> <div align=center> Category: </div> </td> </tr>
<tr> <td>
<INPUT name=for value=<?php echo ("$search_for"); ?>>
</td> <td>
<SELECT NAME=category SIZE=1>
<OPTION <?php if ($search_category == "Search All
Categories") { echo ("SELECTED"); } ?>>Search All Categories
<OPTION <?php if ($search_category == "Floral Creations") {
echo ("SELECTED"); }?>>Floral Creations <OPTION <?php if
($search_category == "Decorative Lighting") { echo
("SELECTED"); }?>>Decorative Lighting <OPTION <?php if
($search_category == "Kitchenware & Crockery") { echo
("SELECTED"); }?>>Kitchenware & Crockery <OPTION <?php if
($search_category == "Fancy Goods & Furniture") { echo
("SELECTED"); }?>>Fancy Goods & Furniture
</SELECT>
</td> <td>
<INPUT TYPE=submit VALUE="Search">
</td>
</form>
<tr> <td> </td> </tr>
</table>
</div>
<?php
switch ($search_category) {
case "":
exit;
break;
case "Search All Categories":
$filter_category = "*" ;
break;
case "Floral Creations":
$filter_category = "floral";
break;
case "Decorative Lighting":
$filter_category = "lighting";
break;
case "Kitchenware & Crockery":
$filter_category = "kitchenware";
break;
case "Fancy Goods & Furniture":
$filter_category = "furniture";
break;
default:
echo ("<P>Error - The Selected Category Was Not Found</P>"); break;
}
$dbcnx = @mysql_connect("server",
"username", "password"); $select =
@mysql_select_db("houseproudlancs_co_uk1"); if ($filter_category ==
"*") {
$command = "SELECT * FROM `stock` WHERE 1 ORDER BY `id`";
} else {
$command = "SELECT * FROM `stock` WHERE 1 AND `category` LIKE
\"$filter_category\" ORDER BY `id`";
}
$qresult = mysql_query($command);
$started_table = false;
while ($row = mysql_fetch_array($qresult)) {
//text search
$the_items_description = $row ["description"];
if ($search_for === '') $search_for = ":X:X::X:X::X:X:"; // hopefully
":X:X::X:X::X:X:" is something that is *never* in $the_items_description
$Items_searchable_text = ($row ["description"] . $row ["id"] . $row
["name"]);
$pos = stristr($Items_searchable_text, $search_for);
//THIS IS FOR DEBUGGING THE TEXT SEARCH
//echo ("POS = ");
//echo ("$pos");
//echo ("<br>item description = ");
//echo ("$the_items_description");
//echo ("<br> search for = ");
//echo ("$search_for");
//echo ("<br>");
//END OF DEBUGGING TEXT SEARCH
if ($search_for == ":X:X::X:X::X:X:") {
$does_contain_text = true;
} elseif ($pos === false) {
$does_contain_text = false;
} else {
$does_contain_text = true;
}
// end text search
if ($does_contain_text == true) {
if ($started_table == false) {
echo ("<center><table width=80% cellpadding=5>"); }
if ($tablebgcolor == "#1E8CDB"){ //blue
$tablebgcolor = "#EBEB96"; //green
} else {
$tablebgcolor = "#1E8CDB"; }
?>
<tr ><td> <table border=0 cellspacing=3 width=100% bgcolor=<?php
echo ("$tablebgcolor"); ?>> <tr><td> <table> <tr>
<?php
switch ($row ["category"]) {
case "lighting":
$item_category = "Decorative Lighting"; break;
case "floral";
$item_category = "Floral Creations";
break;
case "kitchenware":
$item_category = "Kitchenware & Crockery"; break;
case "furniture":
$item_category = "Fancy Goods & Furniture"; break;
default;
$item_category = "Unknown Category";
break;
}
?>
<td><pre>Name: </pre></td> <td><b><div align=left><?php
echo ($row ["name"]); ?> </b></div></td></tr><tr>
<td><pre>Description: </pre></td> <td><div align=left><?php echo
($row ["description"]); ?></div> </td></tr><tr> <td><pre>Category:
</pre></td> <td><div align=left><?php echo ($item_category); ?>
</div> </td></tr><tr> <td><pre>Price:
</pre></td><td><div align=left><?php echo ("£" . $row ["price"]);
?> </div> </td></tr><tr> <td><pre>P&P:
</pre></td><td><div align=left><?php echo ("£" . $row ["pandp"]);
?> </div> </td></tr><tr>
<?php $quantity = $row ["quantity"];
if ($quantity != "0") { ?>
<td><pre>Quantity: </pre></td> <td><div align=left><?php echo
($row ["quantity"]); ?> </div></td></tr><tr><?php } ?>
<td><pre>Product ID: </pre></td> <td><div align=left> <?php
echo ($row ["id"]); ?></div></td></tr><tr><td>
<?php if ($quantity == "0") { ?>
<td><b> <font color=#DD0000> <div align=center>Temporarily Out
Of Stock </b></div></font></tr><tr>
<?php } ?>
</td></tr></table>
</td><td width=30%>
<?php $pictureid = $row ["id"]; ?>
<?php $picturepath = "./images/" . $pictureid . ".jpg"; ?>
<?php
if (file_exists($picturepath)) {
echo ("<div align=\"center\"><a href=\"$picturepath\"
target=LargeImage><img src=$picturepath height=200 alt='Image
Of Product'></a><font size=2><br>Click The Image To See It Full
Size In A New Window</font></div>");
} else {
echo ("<div align=\"center\"><img src=\"/images/nopic.png\"
height=200 alt='No Picture Available'></a><font
size=2><br>Sorry, There Is No Available Picture For This
Item</font></div>");
}
?>
</td></tr></table></td></tr>
<?php
}
}
?>
</table></center>
<?php
?>