dongxianshuai8927 2016-01-29 11:49
浏览 46
已采纳

拆分关键字查询单个零件循环

I have Chinese php search queries.

I want to split up any query up into individual characters.

ex: 你好 (ni hao, hello) split into 你 and 好

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?

  • 写回答

2条回答 默认 最新

  • dongzi3805 2016-01-29 23:08
    关注

    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.

    You could however loop through the array of characters and put together the WHERE part programatically.

    Like this

    $where = array();
    foreach ( $qtwo as $word ) {
       $where[] = "CHS LIKE '%" . $word . "%'";
    }
    
    $where = implode(' OR ', $where);
    

    Use this $where variable in your query

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器