php实现多表搜索的请教
请问我想在_goods表和_logon表同时搜索某些数据,(email,timestamp,tag_main,tag_sub,college,username)下面这句话...
请问我想在_goods表和_logon表同时搜索某些数据,
(email,timestamp,tag_main,tag_sub,college,username)
下面这句话为什么报错?
SELECT email,timestamp,tag_main,tag_sub,college,username
FROM _goods,_logon
WHERE _goods.email like '%$search_words%'
OR _goods.timestamp like '%$search_words%'
OR _goods.tag_main like '%$search_words%'
OR _goods.tag_sub like '%$search_words%'
OR _logon.college like '%$search_words%'
OR _logon.username like '%$search_words%'
AND _goods.active = '1'
ORDER BY id DESC 展开
(email,timestamp,tag_main,tag_sub,college,username)
下面这句话为什么报错?
SELECT email,timestamp,tag_main,tag_sub,college,username
FROM _goods,_logon
WHERE _goods.email like '%$search_words%'
OR _goods.timestamp like '%$search_words%'
OR _goods.tag_main like '%$search_words%'
OR _goods.tag_sub like '%$search_words%'
OR _logon.college like '%$search_words%'
OR _logon.username like '%$search_words%'
AND _goods.active = '1'
ORDER BY id DESC 展开
1个回答
展开全部
你最好粘贴报错内容,一般的错误情况可能是字段名拼写错误导致报告字段名不存在,还可能是两个表有字段名相同的,是的系统无法理解你WHERE后面的这些字段是哪个表的数据。
此外,你的语句结果好像不是你需要的东西,你的这两个表字段清单是否相同的,如果是的话应该用下面的语句:
SELECT '_goods',email,timestamp,tag_main,tag_sub,college,username
FROM _goods
WHERE _goods.email like '%$search_words%'
OR _goods.timestamp like '%$search_words%'
OR _goods.tag_main like '%$search_words%'
OR _goods.tag_sub like '%$search_words%'
OR _logon.college like '%$search_words%'
OR _logon.username like '%$search_words%'
AND _goods.active = '1'
UNION
SELECT '_logon',email,timestamp,tag_main,tag_sub,college,username
FROM _logon
WHERE _goods.email like '%$search_words%'
OR _goods.timestamp like '%$search_words%'
OR _goods.tag_main like '%$search_words%'
OR _goods.tag_sub like '%$search_words%'
OR _logon.college like '%$search_words%'
OR _logon.username like '%$search_words%'
AND _goods.active = '1'
我把语句分开写了,看起来是三段,实际上全部内容在一起才是一个语句。
此外,你的语句结果好像不是你需要的东西,你的这两个表字段清单是否相同的,如果是的话应该用下面的语句:
SELECT '_goods',email,timestamp,tag_main,tag_sub,college,username
FROM _goods
WHERE _goods.email like '%$search_words%'
OR _goods.timestamp like '%$search_words%'
OR _goods.tag_main like '%$search_words%'
OR _goods.tag_sub like '%$search_words%'
OR _logon.college like '%$search_words%'
OR _logon.username like '%$search_words%'
AND _goods.active = '1'
UNION
SELECT '_logon',email,timestamp,tag_main,tag_sub,college,username
FROM _logon
WHERE _goods.email like '%$search_words%'
OR _goods.timestamp like '%$search_words%'
OR _goods.tag_main like '%$search_words%'
OR _goods.tag_sub like '%$search_words%'
OR _logon.college like '%$search_words%'
OR _logon.username like '%$search_words%'
AND _goods.active = '1'
我把语句分开写了,看起来是三段,实际上全部内容在一起才是一个语句。
追问
追答
MYSQLI_QUERY执行失败的使用,请使用MYSQLI_ERROR()函数输出错误的详细原因。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询