Greetings.
After searching through some old posts, I came across a script that would allow for multiple word searches in a MySQL database (i.e. $word1 blah blah blah blah $word2 blah $word3) but I'm having trouble modifying it so that it will search more than one field within a table. The code in question, which was originally posted by Mega can be seen in it's original context here: http://www.phpbuilder.com/board/showthread.php?s=&threadid=10208147
The code itself:
$text = '';
$the_array = explode(' ', $formdata);
$i = 0;
foreach( $the_array AS $t ){
if( $i == 0 ){
$text .= " '%$t%' ";
$i = 1;
}else{
$text .= " OR field LIKE '%$t%' ";
}
}
mysql_query("SELECT * FROM table WHERE field LIKE $text");
How could that be modified to search within three fields while still executing the multiple word search within each field?
I thought of this:
$text = '';
$the_array = explode(' ', $search);
$i = 0;
foreach( $the_array AS $t ){
if( $i == 0 ){
$text .= " '%$t%' ";
$i = 1;
}else{
$text .= " OR field LIKE '%$t%' ";
}
}
$result = mysql_query("SELECT * FROM tapes
WHERE title LIKE $text || date LIKE $text
|| ml LIKE $text ORDER BY 'tape_id'
LIMIT $start,$limit");
But I think it's obvious that will result in an SQL syntax error.
Any suggestions?
Thanks a bunch in advance.
--Tony