gpt4 book ai didi

php - mysql查询错误opencart过滤价格

转载 作者:行者123 更新时间:2023-11-30 22:42:02 26 4
gpt4 key购买 nike

我正在为 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'] ."'" ;
}

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

我收到此错误:“where 子句”中的未知列“special”

最佳答案

在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'

关于php - mysql查询错误opencart过滤价格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30853982/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com