【问题标题】:mysql query mistake opencart filter pricemysql查询错误opencart过滤价格
【发布时间】:2015-06-15 20:00:52
【问题描述】:

我正在为 opencart 2.0 创建过滤器模块 这是我的代码:
模型/目录/product.php
函数 getProducts()

................................... SOME CODES.............
            //Filter products based on slider price range

            if ((isset($this->request->get['lower']))&&(isset($this->request->get['higher'])))
            {
            $sql .=  " AND p.price >='". $this->request->get['lower'] ." ' AND p.price <='". $this->request->get['higher'] ."'" ;
            }

            //Filter products based on price slider

        if (!empty($data['filter_manufacturer_id'])) {
            $sql .= " AND p.manufacturer_id = '" . (int)$data['filter_manufacturer_id'] . "'";
        }

这非常适用于没有特别之处的产品。 但我正在尝试将此代码用于特殊用途。 所以我将我的 SQL 查询更改为:

    if ((isset($this->request->get['lower']))&&(isset($this->request->get['higher'])))
    {
    $sql .=  " AND (CASE WHEN special IS NOT NULL THEN special WHEN discount IS NOT NULL THEN discount ELSE p.price END) >='". $this->request->get['lower'] ." ' AND (CASE WHEN special IS NOT NULL THEN special WHEN discount IS NOT NULL THEN discount ELSE p.price END) <='". $this->request->get['higher'] ."'" ;
    }

但它不适用于具有特殊性的产品。

我收到此错误:Unknown column 'special' in 'where clause'

【问题讨论】:

标签: php mysql opencart opencart2.x


【解决方案1】:

在sql中的WHERE语句之前添加以下内容

LEFT JOIN " . DB_PREFIX . "product_special p2s ON p.product_id = ps.product_id LEFT JOIN " . DB_PREFIX . "product_discount p2d ON p.product_id = pt.product_id

然后在sql上使用'special'作为'p2s.special'和'discount'作为'p2d.discount'

【讨论】:

    猜你喜欢
    • 2012-03-27
    • 2016-04-11
    • 2021-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-01
    • 1970-01-01
    • 2013-04-12
    相关资源
    最近更新 更多