Log in

View Full Version : Multi field search recordset



bigleo23
01-21-2008, 07:23 PM
I am having a problem that I hope someone can help me with? I want to set up a results page that searches about five fields of a table within a database. Basically, I want to setup the recorset so that it catches the word or words from the url and looks within the five fields to see if any of them "contain" the search word.

Can somebody help me

thanks in advance

james438
01-23-2008, 05:59 PM
<?php
$conn = mysql_connect('localhost', 'mysql_user', 'mysql_password') or die(mysql_error());
mysql_select_db("mysql_user",$conn) or die(mysql_error());
$query = "SELECT * FROM tablename WHERE concat(field1,field2,field3) like \"%search%\" and concat(field1,field2,field3) like\"%term%\"";
$res = mysql_query($query);
while ($row = mysql_fetch_array($res, MYSQL_ASSOC)) {
echo "$row[field4]<br><br>";
}
?> Not sure what you mean when you say:
Basically, I want to setup the recorset so that it catches the word or words from the url and looks within the five fields to see if any of them "contain" the search word. but the above script will search 3 fields in a table so that if the two terms are both found in the three fields selected of a table then it will return the result. The last line just prints off an arbitrary field from the row where the two terms were both found.