Re: help with search engine script..pls!
| From: | David Robley | Date: | Fri, 25 Aug 2000 01:29:44 +0000 |
| Subject: | Re: help with search engine script..pls! | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-13555@lists.php.net to get a copy of this message | ||
On 25 Aug, Jason wrote:
> 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);
>
> /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
>
>
<SNIP lotsa code>
>
> Regards
> Jason Savidge
> IT Manager
> One Stop Entertainment
> Brisbane Australia
> www.onestopent.com.au
>
You want to build a query that checks for records that have descript
like stevei or ray or vaughan? Use the array of incoming words to build
a single query string thus (allowing for syntax errors):
$query = "SELECT * FROM prodmast WHERE descript LIKE '%$words[0]%' ";
if count($words) > 1){
foreach($words as $element) {
$query .= " OR descript LIKE '%$element%'";
}
}
$query .= " ORDER BY descript"; /* or whatever else you need */
If you want an option to just search for stevie ray vaugan, let them pop
a radio button, then check the value of that variable and either explode
the words string or not as appropriate.
Cheers
--
David Robley | WEBMASTER & Mail List Admin
RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/
AusEinet | http://auseinet.flinders.edu.au/
Flinders University, ADELAIDE, SOUTH AUSTRALIA