Hey, I am working on a project for my website administration class. Is there a better way to search a table then the following? Basically I am taking a string q and breaking it up into individual words, to find records, the word being search must show up in the data and keywords field.
$qArray = explode(" ",$q);
for($i=0; $i<count($qArray); $i++) {
echo "qArray[$i]: $qArray[$i]<br>\n";
}
$grabMethod = "";
for($i=0; $i<count($qArray); $i++) {
$grabMethod .= "(data LIKE '%" . $qArray[$i] . "%' AND keywords LIKE '%" . $$qArray[$i] . "%')";
if (($i != count($qArray)-1) && (count($qArray) > 1)) {
$grabMethod .= " AND ";
}
}
$result = mysql_query("SELECT address FROM data WHERE " . $grabMethod) or die(mysql_error());
Thank you for your input!
Jason