Page 1 of 1

Product Search Engine?

Posted: Tue Dec 03, 2002 4:01 pm
by JPlush76
Hey all,
Trying to find the best way to go about this...

I want to create a search function on our website

now if someone types in the word CAMERA I can do a query that will

SELECT fields FROM products WHERE field1 LIKE "camera" or field2 LIKE "camera"

but what should I do if they enter more than one word? like DIGITAL CAMERA

being that I'd want them to see everything with the words DIGITAL and CAMERA not just the products with "DIGITAL CAMERA" right next to each other.

Do I have to explode into an array? Anyone have experience with this? thanks!

Posted: Tue Dec 03, 2002 5:12 pm
by JPlush76
think I got it

Code: Select all

<?php
$formdata = $_SESSION['search_term'];

$text = '';
$the_array = explode(' ', $formdata);
$i = 0;

foreach($the_array AS $t){
if( $i == 0 ){
$text .= " (products_name LIKE '%$t%' OR products_description LIKE '%$t%' OR products_model LIKE '%$t%') ";
$i = 1;
}else{
$text .= " AND (products_name LIKE '%$t%' OR products_description LIKE '%$t%' OR products_model LIKE '%$t%') ";
}
}
?>