Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
针对两个php变量的多表全文搜索_Php_Mysql_Html - Fatal编程技术网

针对两个php变量的多表全文搜索

针对两个php变量的多表全文搜索,php,mysql,html,Php,Mysql,Html,我有三个信息表,其中业务id是公共线程。我有两个输入字段,一个用于一般搜索(用户可以搜索他们想要的任何内容)和一个zip输入。在php端,我捕获常规搜索字符串并将其设置为$search,将zip设置为$zip 如何使用$search变量匹配任何全文索引,然后使用$zip限制这些匹配,然后只返回表c中的id 我的数据库结构如下: table coup id << this is the my desired information from the search ti

我有三个信息表,其中业务id是公共线程。我有两个输入字段,一个用于一般搜索(用户可以搜索他们想要的任何内容)和一个zip输入。在php端,我捕获常规搜索字符串并将其设置为
$search
,将zip设置为
$zip

如何使用
$search
变量
匹配
任何全文索引,然后使用
$zip
限制这些匹配,然后只返回表c中的id

我的数据库结构如下:

table coup
    id  << this is the my desired information from the search
    timestamp
    business_id
    coupvalue
    startdate
    enddate
    username
    status
    terms
    image
    description
        primary = id
        fulltext = name
table bloc
    id
    address
    city
    state
    zip
    business_id
    phone
    lat
    lon
        primary = id
table bus
    business_id
    name
    timestamp
    category
    subcat
        primary = business_id
        fulltext = name,category,subcat
表耦合

id您可以对匹配项使用
条件:

select
    c.id
from
    coup c
    inner join bus b on
        c.business_id = b.business_id
    inner join block z on
        c.buisness_id = z.business_id
    where
        (match(c.name) against ('$search')
        or match (b.name, b.category, b.subcat) against ('$search'))
        and z.zip = '$zip'
我尚未对其进行基准测试,但这可能会更快:

select
   c.id
from
    (select id, business_id 
     from coup 
     where match(name) against ('$search')
    ) as c
    left join
       (select business_id 
        from bus 
        where match(name, category, subcat) against ('$search')
       ) as b on
        c.business_id = b.business_id 
    inner join bloc z on
        c.business_id = z.business_id
where
    z.zip = '$zip'

不过我想将c.name、b.category、b.subcat添加到匹配中。全文搜索只在各自的索引中起作用。据我所知,您不能进行多表全文索引。