liquorvicar wrote:As bogu says, you could use a FULLTEXT index/search. However this is a native MySQL function and isn't portable. For full portability you might want to build your own search engine function. There's a good article about doing the later in the Sept issue of PHP Architect
Note, however, that virtually every database made has some kind of full text indexing feature. MSSQL, Oracle, PostgreSQL, DB2, all have full text search engines. Generally they're more work up front, and often the indexes aren't updated in real time, but they're much much faster at looking up various text entries in the database than the other way.
OTOH, if your tables aren't real big, it's quite easy to build a search query that hits x fields with y words.
For instance:
<?php
$query = "select * from table where (";
$words = array("hello","again");
$fields = array("field1","field2","field3");
$l=0;
foreach ($words as $w){
if ($l!=0) $query.=") AND (";
$l=1;
$m=0;
foreach($fields as $f){
if ($m!=0) $query.=" OR ";
$query.=" $f like '%$w%' ";
$m=1;
}
}
$query.=")";
print $query;
?>
Just change your array entries and you can search for more words on more fields etc... I leave it to you to parse a search string into individual words and put them in an array. (hint, explode is good for that)