RE: [PHP-DB] Searching a variable

From: Date: Thu, 17 Jan 2002 02:48:13 +0000
Subject: RE: [PHP-DB] Searching a variable
Groups: php.db 
Request: Send a blank email to php-db+get-15907@lists.php.net to get a copy of this message
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:chris@planetoxygene.com] // Sent: Thursday, 17 January 2002 10:34 AM // To: php-db@lists.php.net // 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 //

« previous php.db (#15907) next »