How set AND condition to ALL columns - php(如何将 AND 条件设置为所有列 - php)
问题描述
在我的表格中,如果我输入
floor fly
表返回没有匹配的记录,因为全局搜索 php 函数搜索单个列内的记录.
但我希望 AND 条件适用于所有列.
table returns No matching records because Global Search php function search records inside a SINGLE column.
But I want that AND condition works to ALL columns.
如果我输入 floor fly 表格,我应该显示如下内容:
If I type floor fly table should me display something like:
|__Column1___|___Column2____|__Column4_|
| | | |
|..FLOOR... |DREAMS - FLY | 1994 |
| ..dreams | xyz | floor |
注意:这不是 OR 函数 abc OR cde
这是我的 php 代码,但不像我期望的那样工作:
Attention: this is not a OR function abc OR cde
This is my php code but AND don't work like as I expect:
static function filter ( $request, $columns, &$bindings )
{
$globalSearch = array();
$columnSearch = array();
$dtColumns = self::pluck( $columns, 'dt' );
if ( isset($request['search']) && $request['search']['value'] != '' ) {
$str = $request['search']['value'];
for ( $i=0, $ien=count($request['columns']) ; $i<$ien ; $i++ ) {
$requestColumn = $request['columns'][$i];
$columnIdx = array_search( $requestColumn['data'], $dtColumns );
$column = $columns[ $columnIdx ];
if ( $requestColumn['searchable'] == 'true' ) {
$binding = self::bind( $bindings, '%'.$str.'%', PDO::PARAM_STR );
$globalSearch[] = "".$column['db']." LIKE ".$binding;
}
}
}
消除对我想要的任何疑问:LOOK
To dispel any doubts on what I want: LOOK
这是我想要的示例图片
推荐答案
好吧,您应该决定要使用的搜索条件.如果您希望使用特定短语匹配,并且不想使用全文搜索,您应该重建您的查询,如:
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';
在你的 PHP 代码中,它应该是这样的(你没有指定输入数据格式,所以我假设你使用$str"作为空格分隔的文本,并且想要检查$str"中的所有单词搜索词组:
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;
}
这篇关于如何将 AND 条件设置为所有列 - php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何将 AND 条件设置为所有列 - php
基础教程推荐
- PHP 类:全局变量作为类中的属性 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何替换eregi() 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
