[PHP-DB] Searching a variable

2002-01-16 Thread Chris Payne

Hi there everyone,

Thanks for all the help recently everyone, it's very appreciated.  I just have one 
last question if that's ok :-)

I have a string taken from a form, now this string could contain 1 word or it would 
contain 10, what I need to know is how do I search a DB for each word in the string?  
I have a simple search engine which works great for works next to each other in the DB 
but I need it to search each entry for ALL words entered, whether they are next to 
each other in the DB or 3 words apart, how can I do this?

Thanks for all your help.

Regards

Chris Payne
www.planetoxygene.com



RE: [PHP-DB] Searching a variable

2002-01-16 Thread Beau Lebens

i don't doubt that there are probably better ways of going about this chris,
but you can do something like;

?php
$words = explode( , $searchText);

$query = SELECT * FROM table WHERE ;
foreach ($words as $word) {
$query .= field LIKE '%word%' AND ;
}
$query .= field!='' ORDER BY something;

$results = mysql_query($query);
?

as for ranking the results - i have heard people mentioning the fulltext
index in mysql, and there's some cool calculations floating around in the
archives somewhere, but they escape me at the moment and i haven't got
around to implementing a decent search engine yet :)

// -Original Message-
// From: Chris Payne [mailto:[EMAIL PROTECTED]]
// Sent: Thursday, 17 January 2002 10:34 AM
// To: [EMAIL PROTECTED]
// Subject: [PHP-DB] Searching a variable
// 
// 
// Hi there everyone,
// 
// Thanks for all the help recently everyone, it's very 
// appreciated.  I just have one last question if that's ok :-)
// 
// I have a string taken from a form, now this string could 
// contain 1 word or it would contain 10, what I need to know 
// is how do I search a DB for each word in the string?  I have 
// a simple search engine which works great for works next to 
// each other in the DB but I need it to search each entry for 
// ALL words entered, whether they are next to each other in 
// the DB or 3 words apart, how can I do this?
// 
// Thanks for all your help.
// 
// Regards
// 
// Chris Payne
// www.planetoxygene.com
// 

-- 
PHP Database 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]