help with search engine script..pls!
| From: | Jason | Date: | Fri, 25 Aug 2000 01:08:42 +0000 |
| Subject: | help with search engine script..pls! | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-13552@lists.php.net to get a copy of this message | ||
hi all
below is a script that i am trying to get to work....
the echo statements are only there to help me with my debugging so far.....
we are a cd wholesaler and i need a search engine to search our catalogue online....
i have a simple one working okay but only on a one word search so the one below i was trying to get it to work on an artist like Stevie Ray Vaughan
so i would like it to explode that into an array "Stevie" "Ray" "Vaughan" and then search for any of those words appearing in our database.
i would like the words in the array returned to the screen to say
You searched for Stevie Ray Vaughan
12 Matched Results
i would also like for the customer to be able to search for exact match or any words etc so that stevie ray vaughan would not bring up sarah vaughan or jimmie vaughan etc. this could be chosen just from a simple drop down menu..
thanks you in advance for any help you can give me.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$keyword = strtoupper($keyword);
$words = explode(" ", $keyword);
echo (count ($words));
if ($words)
{
$db=mysql_connect("localhost","user","password");
mysql_select_db("database",$db);
for ( $i = 0; $i <= count($words); $i++ )
{
$query = "SELECT * FROM prodmast WHERE descript LIKE "%$words[$i]%" ";
echo ($query);
}
echo "words1 = $words[0]";
echo "words2 = $words[1]";
echo (count ($words));
$result = mysql_query($query);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
The code below is the full search engine script including the above snippet
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
<html>
<head>
<title>Search One Stop Database</title>
</head>
<body bgcolor=#ffffff topmargin = 0>
<font face=verdana,arial,sans serif color=#006699 size=2>
<table width = 100% align = "left" border = 0 cellspacing = "0" cellpadding = "5">
<tr>
<td colspan=2><font size=4 font face=verdana,arial,sans serif color=#006699><b>One Stop Catalogue Search</b></font><br>
<font color="#006699" face="Verdana, Arial, Helvetica, sans-serif" size="1">Please search by first or last name of artist or any part of the title you are looking for.</font></font></td>
</tr>
<form method=post action="<?php echo $PHP_SELF ?>">
<tr>
<td width = 200 bgcolor = #cccccc valign="middle" align="left"> <font size=2 font face=verdana,arial,sans serif color=#006699>
<font color="#006699" face="Verdana, Arial, Helvetica, sans-serif" size="1"><b>Search
by:</b></font></font> <font color="#006699" face="Verdana, Arial, Helvetica, sans-serif" size="1">
<SELECT NAME="value">
<option value="descript">Artist or Title
<option value="code">Catalogue No.
</select>
</font> </td>
<td width = 300 bgcolor = #cccccc valign="middle" align="left">
<input type=text name="keyword" size=25>
<input type=submit value="Search">
</td>
</tr>
</form>
<br><?php $keyword = strtoupper($keyword); $words = explode(" ", $keyword); echo (count ($words)); if ($words) { $db=mysql_connect("localhost","user","password"); mysql_select_db("database",$db);
for ( $i = 0; $i <= count($words); $i++ )
{
$query = "SELECT * FROM prodmast WHERE descript LIKE "%$words[$i]%" ";
echo ($query);
}
echo "words1 = $words[0]";
echo "words2 = $words[1]";
echo (count ($words));
$result = mysql_query($query);
if ($result)
{
echo "<tr><td colspan = 2><font size=2 color=#006699 face=verdana, arial, sans serif>Search Results for <b><font size=2 color=#FF0000 face=verdana, arial, sans serif>$keyword</font></b></font></td></tr>\n";
echo "<tr><td colspan = 6>";
echo ("<TABLE width = 100% align = left CELLPADDING=4 CELLSPACING=0 border = 0 FONT FACE=VERDANA SIZE=1 COLOR=#006699>\n");
echo ("<tr bgcolor=#006699>
<td width = 15%><b><font face=Verdana, Helvetica, sans-serif size=-2 color=#ffffff>Catalogue No</font></b></td>
<td width = 50%><b><font face=Verdana, Helvetica, sans-serif size=-2 color=#ffffff>Artist/Title</font></b></td>
<td width = 10%><b><font face=Verdana, Helvetica, sans-serif size=-2 color=#ffffff>Pre GST</font></b></td>
<td width = 10%><b><font face=Verdana, Helvetica, sans-serif size=-2 color=#ffffff>Unit</font></b></td>
<td width = 10%><b><font face=Verdana, Helvetica, sans-serif size=-2 color=#ffffff>Supplier</font></b></td>
<td width = 5%><b><font face=Verdana, Helvetica, sans-serif size=-2 color=#ffffff>Qty</font></b></td>
</tr>\n");
while ($r = mysql_fetch_array($result)) {
$code = $r["code"];
$descript = $r["descript"];
$unit = $r["unit"];
$supp1 = $r["supp1"];
$instock = $r["instock"];
$wsale = $r["wsale"];
/* Output to nested tables */
echo "<TR>";
echo "<TD width = 15%><FONT COLOR=#000000><FONT SIZE=1>$code</FONT></FONT>";
echo "<TD width = 50%><B><FONT COLOR=#FF6600><FONT SIZE=1>$descript</a></FONT></FONT></B>";
echo "<TD width = 10%><FONT COLOR=#000000><FONT SIZE=1>$wsale</FONT></FONT>";
echo "<TD width = 10%><FONT COLOR=#000000><FONT SIZE=1>$unit</FONT></FONT>";
echo "<TD width = 10%><FONT COLOR=#000000><FONT SIZE=1>$supp1</FONT></FONT>";
echo "<TD width = 5%><FONT COLOR=#000000><FONT SIZE=1>$instock</FONT></FONT>";
echo "</TR>";
}
}
else
{
echo "No Data.";
}
}else if ($code) { $result = mysql_query("SELECT * FROM prodmast WHERE code=$code",$db); $r = mysql_fetch_array($result); echo "Catalogue No.: $code\n<br>"; echo "Artist/Title: $descript\n<br>"; } ?> </table> </font> </body> </html> Regards Jason Savidge IT Manager One Stop Entertainment Brisbane Australia www.onestopent.com.au