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!
Product Search Engine?
Moderator: General Moderators
-
JPlush76
- Forum Regular
- Posts: 819
- Joined: Thu Aug 01, 2002 5:42 pm
- Location: Los Angeles, CA
- Contact:
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%') ";
}
}
?>