我一直在尝试使用 $keyword 中的 where site_keywords 从数据库中检索所有 site_keywords。但它没有显示任何错误或输出。
$user_query = $_REQUEST['user_query'];
$search=preg_split('/\s+/',$user_query);
$keywords = join(",",$search);
$query = "select * from sites where site_keywords in ('%$keywords%') order by rank DESC ";
有人可以帮我解决这个问题吗?
最佳答案
连接(内爆)函数中缺少一些单引号:
$user_query = $_REQUEST['user_query'];
$search=preg_split('/\s+/',$user_query);
$keywords = join("','",$search);
$query = "select * from sites where site_keywords in ('%$keywords%') order by rank DESC ";
不带这些引号的查询:
...where site_keywords in ('one,two,three')...
这不会产生任何输出或错误,因为没有有效结果。搜索查询被视为一个长字符串。
使用这些报价进行查询:
...where site_keywords in ('one','two','three')...
这里每个查询都正确地拆分为多个搜索值。
关于php - 如何在 php mysql 查询中使用数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44969901/