php - 复杂的元查询不起作用

标签 php mysql wordpress

我有一个非常复杂的元查询,分为两部分。每个部分单独工作都很好,但是当我将两个部分与 or 进行比较时,它应该显示两个结果的组合,但它没有显示任何内容。

第一个片段

array(
    'relation'      => 'AND',
    array(
        'relation'      => 'AND',
        array(
            'key'       => 'range1_min',
            'value'     => floatval($_GET['m']),
            'type'      => 'DECIMAL',
            'compare'   => '<='
        ),
        array(
            'key'       => 'range1_max',
            'value'     => floatval($_GET['m']),
            'type'      => 'DECIMAL',
            'compare'   => '>='
        )
    ),
    array(
        'relation'      => 'AND',
        array(
            'key'       => 'range1_min',
            'value'     => floatval($_GET['n']),
            'type'      => 'DECIMAL',
            'compare'   => '<='
        ),
        array(
            'key'       => 'range1_max',
            'value'     => floatval($_GET['n']),
            'type'      => 'DECIMAL',
            'compare'   => '>='
        )
    )
);

第二个片段

array(
    'relation'      => 'AND',
    array(
        'relation'      => 'AND',
        array(
            'key'       => 'range2_min',
            'value'     => floatval($_GET['m']),
            'type'      => 'DECIMAL',
            'compare'   => '<='
        ),
        array(
            'key'       => 'range2_max',
            'value'     => floatval($_GET['m']),
            'type'      => 'DECIMAL',
            'compare'   => '>='
        )
    ),
    array(
        'relation'      => 'AND',
        array(
            'key'       => 'range2_min',
            'value'     => floatval($_GET['n']),
            'type'      => 'DECIMAL',
            'compare'   => '<='
        ),
        array(
            'key'       => 'range2_max',
            'value'     => floatval($_GET['n']),
            'type'      => 'DECIMAL',
            'compare'   => '>='
        )
    )
);

它们各自都工作正常,但当我将它们与“OR”条件放在一起时,它们就无法工作。

完整代码片段

array(
    'relation'      => 'OR',
    array(
        'relation'      => 'AND',
        array(
            'relation'      => 'AND',
            array(
                'key'       => 'range1_min',
                'value'     => floatval($_GET['m']),
                'type'      => 'DECIMAL',
                'compare'   => '<='
            ),
            array(
                'key'       => 'range1_max',
                'value'     => floatval($_GET['m']),
                'type'      => 'DECIMAL',
                'compare'   => '>='
            )
        ),
        array(
            'relation'      => 'AND',
            array(
                'key'       => 'range1_min',
                'value'     => floatval($_GET['n']),
                'type'      => 'DECIMAL',
                'compare'   => '<='
            ),
            array(
                'key'       => 'range1_max',
                'value'     => floatval($_GET['n']),
                'type'      => 'DECIMAL',
                'compare'   => '>='
            )
        )
    ) ,
    array(
        'relation'      => 'AND',
        array(
            'relation'      => 'AND',
            array(
                'key'       => 'range2_min',
                'value'     => floatval($_GET['m']),
                'type'      => 'DECIMAL',
                'compare'   => '<='
            ),
            array(
                'key'       => 'range2_max',
                'value'     => floatval($_GET['m']),
                'type'      => 'DECIMAL',
                'compare'   => '>='
            )
        ),
        array(
            'relation'      => 'AND',
            array(
                'key'       => 'range2_min',
                'value'     => floatval($_GET['n']),
                'type'      => 'DECIMAL',
                'compare'   => '<='
            ),
            array(
                'key'       => 'range2_max',
                'value'     => floatval($_GET['n']),
                'type'      => 'DECIMAL',
                'compare'   => '>='
            )
        )
    )
);

如有任何帮助,我们将不胜感激。

最佳答案

当我生成 wordpress 的 sql 查询并在 phpmyadmin 上运行它时,它生成错误并说我已经超出了默认连接设置,这意味着在我的查询中我有太多连接。

我已通过在 wordpress 查询之前手动放置此 sql 查询来解决此错误。

global $wpdb
$wpdb->query("SET SQL_BIG_SELECTS = 1");

关于php - 复杂的元查询不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31367800/

相关文章:

php - 搜索结果无法显示分页

php - 使用表单的搜索/过滤器分页

php - WordPress mysql 查询也可获取特色图像

php - WooCommerce 从所有订单中获取项目元数据

javascript - 如何跟踪退出链接

Php, 正则表达式

mysql - 收到连接错误连接必须有效且打开

php - jqgrid中url :server. php 和 url :server. php?q=1 之间的区别

php - PHP 中的 Mongodb MapReduce

php - 在 YII 中使用 ExtJS