How set AND condition to ALL columns - php

前端 未结 2 1820
粉色の甜心
粉色の甜心 2021-01-22 12:18

In MY TABLE if I type

floor fly

table returns No matching records because Global Search php function search records insid

2条回答
  •  -上瘾入骨i
    2021-01-22 12:43

    well, you should decide what search criteria you want to use. If you want you use match by certain phrase, and do not want to use FULL TEXT search, you should rebuild your query like:

    SELECT * FROM a WHERE a.col1 REGEXP 'text1|text2|text3' OR a.col2 REGEXP 'text1|text2|text3';
    

    In your PHP code, it should be smth like this (you did not specify input data format, so I assume, you are using "$str" as space separated text, and want to check all words in "$str" phrase for search:

    if ( $requestColumn['searchable'] == 'true' ) {
       $str = str_replace(" ","|",$str);
       $binding = self::bind( $bindings, $str, PDO::PARAM_STR );
       $globalSearch[] = "".$column['db']." REGEXP ".$binding;
    }
    

提交回复
热议问题