RE: [PHP-DB] how to do a search in mysql database for multiple keywords??

From: Date: Mon, 15 Oct 2001 11:34:41 +0000
Subject: RE: [PHP-DB] how to do a search in mysql database for multiple keywords??
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-13323@lists.php.net to get a copy of this message
Another solution would also be to use the FULLTEXT functions availble in MySQL... it is by far faster than this query. To do so, your fields must be of type VARCHAR and TEXT. Then create a FULLTEXT index on these fields by issuing the following command: ALTER TABLE <tablename> ADD FULLTEXT(<column1>,<column2>,<ccolumn3>) Then your query would look like: SELECT *, MATCH(<field1>,<field2>,<field3> ) AGAINST ('$qiery' ) AS score FROM Messages WHERE MATCH( <field1>,<field2>,<field3> ) AGAINST ( '$query' ) ORDER BY score DESC; This would return the results in order of relevance... works pretty good :) -- ------------------------------------------------------------------------ James "Mike" Patton \ Professional web applications developer mpatton@acuitymedia.com \ Specializing in PERL, MySQL, PHP and JAVA ------------------------------------------------------------------------ On 2001.10.15 04:08 Dave Watkinson wrote: > SELECT > <columnlist> > FROM > <tablename> > WHERE > <column to be searched> > LIKE > '%<word1>%' > AND > <column to be searched> > LIKE > '%<word2>%' > AND > <column to be searched> > LIKE > '%<word3>%' > > for example... > > SELECT uid, name, address, email FROM people WHERE address LIKE > '%london%' AND address LIKE '%baker%' AND address LIKE '%221b%' > > In MySQL the % sign is the wildcard, so '%baker%' will look for all > instances containing baker. Similarly baker% will match all strings > starting with baker and baker% will match all strings ending in baker. > > > Hope this helps > > > Dave > > > > -----Original Message----- > From: Nicklas Bondesson [mailto:nicklas.bondesson@eds.com] > Sent: 15 October 2001 09:06 > To: php-db@lists.php.net > Subject: [PHP-DB] how to do a search in mysql database for multiple > keywords?? > > > need some help on this. > > any ideas?? > > /nicke > > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > For additional commands, e-mail: php-db-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > For additional commands, e-mail: php-db-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.db (#13323) next »