RE: [PHP] split keyword in search engine

From: Date: Mon, 07 Aug 2000 12:53:09 +0000
Subject: RE: [PHP] split keyword in search engine
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-10458@lists.php.net to get a copy of this message
Hi. You could use explode() to split up the string (by whitespace), and generate a SQL query from it. $words = explode(" ", $criteria); $query = "SELECT * FROM prodmast WHERE "; for ( $i = 0; $i < count( $words ) - 1; $i++ ) { $query =. " descript LIKE %" . $words[$i] . "% OR "; } $query =. " descript LIKE %" . $words[$i] . "%"; $q = mysql_query( $query ); ...blah... -- Lars Wilhelmsen <lw@ez.no>, developer @ eZ systems <www.ez.no> -----Original Message----- From: SRV [mailto:bebox@dingoblue.net.au] Sent: 7. august 2000 14:41 To: php-general@lists.php.net Subject: [PHP] split keyword in search engine hi all i have done a basic search engine for our customers to search our cd database. the problem is that our records are stored with last name first eg Hendrix Jimi rather than Jimi Hendrix...so the way i have my search engine now, if you did a search for jimi hendrix it would come back with nothing but a search for hendrix or hendrix jimi would find everything fine. i have included my code below so i'm trying to figure out how to split the keyword and then search for all parts of it.. can any pls help.... i have looked at the php manual but this is not really covered to the extent that my feeble brain can comprehend..too much purple haze i'd say ;-) <?php $keyword = strtoupper($keyword); if($keyword) { $db=mysql_connect("localhost","username","password"); mysql_select_db("onestop",$db); if($value==code){ $sql="SELECT * FROM prodmast WHERE code LIKE '%$keyword%' order by descript"; } else if($value==descript){ $sql="SELECT * FROM prodmast WHERE descript LIKE '%$keyword%' order by descript"; } $result=mysql_query($sql); thanks jason -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#10458) next »