if I give the user a search and he enters 'cat dog' I am going to want to
find all the results that have the word 'cat' or 'dog' in them, but I want
all the results that have 'cat' and 'dog' at the beginning of the results
because these would be more relevent. now how I see it is this, it aint
pretty.
$result = select * from product where product_feature like '%cat%' and
product_feature like '%dog%'
foreach( $result as $pos => $val )
$name[$val['product_id']] = $val['product_name']
$result = select * from product where product_feature like '%cat%' or
product_feature like '%dog%'
foreach( $result as $pos => $val )
$name[$val['product_id']] = $val['product_name']
foreach( $name as $pos => $val )
echo "$val <br>";
this will put the 'AND' before the 'OR'. but its not nice, would be nice if
I could do this with one simple query. this is only with two keywords. with
three its gets exponentially nasty.
'cat dog mouse'
$result = select * from product where product_feature like '%cat%' and
product_feature like '%dog%' and product_feature like '%mouse%'
foreach( $result as $pos => $val )
$name[$val['product_id']] = $val['product_name']
$result = select * from product where product_feature like '%cat%' and
product_feature like '%dog%'
foreach( $result as $pos => $val )
$name[$val['product_id']] = $val['product_name']
$result = select * from product where product_feature like '%cat%' and
product_feature like '%mouse%'
foreach( $result as $pos => $val )
$name[$val['product_id']] = $val['product_name']
$result = select * from product where product_feature like '%dog%' and
product_feature like '%mouse%'
foreach( $result as $pos => $val )
$name[$val['product_id']] = $val['product_name']
$result = select * from product where product_feature like '%cat%' or
product_feature like '%dog%' or product_feature like '%mouse%'
foreach( $result as $pos => $val )
$name[$val['product_id']] = $val['product_name']
foreach( $name as $pos => $val )
echo "$val <br>";
ouch, this is just nasty, not good. there must be a better way. accually
writing code to take a dynamic number of keywords is guna be ugly.
any SQL idea's ? yes I know this is a php forum, but its related.
--
Chris Lee
[EMAIL PROTECTED]
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]