让PHP搜索一切

时间:2011-06-14 00:32:34

标签: php mysql search

我想知道如何在搜索数据库中搜索更多的表来包含城市和搜索。城市和搜索已经在我的数据库中,我需要做的就是搜索它们,但我不知道如何。

这是我到目前为止所做的:

//explode out search term
$search_exploded = explode(" ",$search);

foreach($search_exploded as $search_each) {

//construct query
$x++;
if ($x==1)
    $construct .= " keywords LIKE '%$search_each%'";
else
    $construct .= " OR keywords LIKE '%$search_each%'";
}

1 个答案:

答案 0 :(得分:2)

将代码更改为:

foreach($search_exploded as $search_each) {
    //construct query
    $x++;

    if ($x==1)
        $construct .= " keywords LIKE 
            '%$search_each%' OR city LIKE '%$search_each%' or state LIKE 
            '%search_each%'";
    else
        $construct .= " OR keywords LIKE 
            '%$search_each%' OR city LIKE 
            '%$search_each%' or state LIKE '%search_each%'";
}