我正在尝试修改搜索路由,我有两个字段,艺术家和标题,当我搜索伪装者 Foo Fighters 时,我没有得到任何结果,而如果我单独搜索,我会得到。任何帮助将不胜感激谢谢。
$arraySearch = explode(" ", $searchvalue);
$arrayFields = array(0 => "Artist", 1 => "Title");
$countSearch = count($arraySearch);
$a = 0;
$b = 0;
$query = "SELECT * FROM ".$table." WHERE (";
$countFields = count($arrayFields);
while ($a < $countFields)
{
while ($b < $countSearch)
{
$query = $query."$arrayFields[$a] LIKE '%$arraySearch[$b]%'";
$b++;
if ($b < $countSearch)
{
$query = $query." AND ";
}
}
$b = 0;
$a++;
if ($a < $countFields)
{
$query = $query.") OR (";
}
}
$query = $query.")";
$query_result = mysql_query($query);
echo '<h1>Your Search Results</h1>'."\n\n";
if(mysql_num_rows($query_result) < 1)
{
echo '<p>No matches found for "'.$searchvalue.'"</p>';
}
else
{
echo '<p>Search Results for "'.$searchvalue.'":</p>'."\n\n";
while($row = mysql_fetch_assoc($query_result))
{
// output
}
}