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


- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01