当where子句具有指定值时,单个过滤器不起作用 [英] Single filter not working when where clause have specified value

查看:76
本文介绍了当where子句具有指定值时,单个过滤器不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将数据表设置为仅显示以 OQC 开头的数据。

I set my datatable only show data which start with OQC.

require('ssp.class.join.php' );

    $joinQuery = "FROM `monitor` AS `a` JOIN `sym_category` AS `b` JOIN `model_cat` AS `c`";
    $joinQuery.= "ON (`b`.`id_sym` = `a`.`id_sym`) AND (`c`.`id_mod` = `a`.`id_mod`)";
    $joinQuery.= " WHERE `a`.`id_car` LIKE 'OQC%'";

    echo json_encode(
       SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns, $joinQuery )
    );

ssp.class.join.php:

ssp.class.join.php :

static function filter ( $request, $columns, &$bindings, $isJoin = false )
    {
        $globalSearch = array();
        $columnSearch = array();
        $dtColumns = SSP::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 = SSP::bind( $bindings, '%'.$str.'%', PDO::PARAM_STR );
                    $globalSearch[] = ($isJoin) ? $column['db']." LIKE ".$binding : "`".$column['db']."` LIKE ".$binding;
                }
            }
        }

        // Individual column filtering
        for ( $i=0, $ien=count($request['columns']) ; $i<$ien ; $i++ ) {
            $requestColumn = $request['columns'][$i];
            $columnIdx = array_search( $requestColumn['data'], $dtColumns );
            $column = $columns[ $columnIdx ];

            $str = $requestColumn['search']['value'];

            if ( $requestColumn['searchable'] == 'true' &&
                $str != '' ) {
                $binding = SSP::bind( $bindings, '%'.$str.'%', PDO::PARAM_STR );
                $columnSearch[] = ($isJoin) ? $column['db']." LIKE ".$binding : "`".$column['db']."` LIKE ".$binding;
            }
        }

        // Combine the filters into a single string
        $where = '';

        if ( count( $globalSearch ) ) {
            $where = '('.implode(' OR ', $globalSearch).')';
        }

        if ( count( $columnSearch ) ) {
            $where = $where === '' ?
                implode(' AND ', $columnSearch) :
                $where .' AND '. implode(' AND ', $columnSearch);
        }

        if ( $where !== '' ) {
            $where = 'WHERE '.$where;
        }

        return $where;
    }

显示错误:'WHERE a附近的语法错误。 id_car .....'
我应该更改哪一部分才能使它们都正常工作?

Show error : syntax error near 'WHERE a.id_car.....'. Which part should i change, to make both working?

推荐答案

您可能应该看看那是beeing的确切查询级联,因为其中存在语法错误。尝试查看最后的 $ where (或者更好的是整个查询,因为那是错误的内容)

You should probably look at the exact query thats beeing concatenated, since theres a syntax error in it. Try to look at what $where becomes in the end (or better, the entire query, since thats whats has the error)

猜测,最后一行的开头可能需要空格

Guessing, theres possibly a need for a space at the start of your last line

   $where = ' WHERE '.$where;

这篇关于当where子句具有指定值时,单个过滤器不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆