php - 让 PHP 搜索一切

标签 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%'";
}

最佳答案

将代码更改为:

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%'";
}

关于php - 让 PHP 搜索一切,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6337907/

相关文章:

php - 填充两个文本字段后显示数据

arrays - 在字符串数组中查找特定字符/字母的算法?

arrays - 在紧密排序的元素数组中搜索元素的最坏情况时间复杂度?

linux - 搜索多个目录并返回一个结果

php - 如何在核心php中实现mvc

php - 你什么时候使用 mysqli 和 ssl (ssl_set)

php - Wordpress 无代码 slider 响应问题

php - 我应该使用 php 还是我的 sql 将数据插入表中

php - 将输入值存入数据库

javascript - 使用ajax将对象数组发送到php并提交到SQL