[英]Split up keyword query individual parts loop
I have Chinese php search queries. 我有中文php搜索查询。
I want to split up any query up into individual characters. 我想将任何查询拆分成单个字符。
ex: 你好 (ni hao, hello) split into 你 and 好 例如:你好(ni hao,hello)分为你和好
my query is set like: 我的查询设置为:
$q = $_REQUEST["q"];
the results I want to split is set up like: 我要拆分的结果设置如下:
$results4 = $db->query( "SELECT CHS, PIN, DEF FROM FOUR
WHERE CHS LIKE '%".$q."%' OR PIN LIKE '%".$q."%'");
while ($row4 = $results4->fetchArray()) {
How can I split up the keyword and look up all the components? 如何拆分关键字并查找所有组件?
If you want it all in one query you will have to generate the whole query. 如果要在一个查询中全部完成,则必须生成整个查询。 If you were looking for an exact match you could use something similar to the
in_array()
function, but with LIKE
it doesn't work. 如果您正在寻找完全匹配的内容,则可以使用类似于
in_array()
函数的方法,但使用LIKE
则无法使用。
You could however loop through the array of characters and put together the WHERE
part programatically. 但是,您可以遍历字符数组,并以编程方式将
WHERE
部分组合在一起。
Like this 像这样
$where = array();
foreach ( $qtwo as $word ) {
$where[] = "CHS LIKE '%" . $word . "%'";
}
$where = implode(' OR ', $where);
Use this $where
variable in your query 在查询中使用此
$where
变量
您可以使用str_split转换字符数组中的字符串
$chars = str_split($q)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.