opencart未执行正确的mysql查询

rbl8hiat  于 2021-06-21  发布在  Mysql
关注(0)|答案(0)|浏览(213)

我在orders表(shopper\u id)中添加了一个新的列,我试图用新的列条件获取数据,但结果返回空查询是正确的,当我直接执行它时,它返回正确的结果
敞篷车公式

SELECT o.order_id, o.firstname, o.lastname, os.name as status, o.date_added,o.shopper_id as shopper_id  , o.total, o.currency_code, o.currency_value FROM  `" . DB_PREFIX . "order` o LEFT JOIN " . DB_PREFIX . "order_status os ON (o.order_status_id = os.order_status_id) WHERE  o.store_id = '" . (int) $store_id . "' AND o.order_status_id = '" . (int) $status . "' AND os.language_id = '" . (int) $this->config->get('config_language_id') . "' AND ( o.shopper_id = NULL OR o.shopper_id = '0' )  ORDER BY o.order_id DESC

下面是我的mysql查询-

SELECT o.order_id, o.firstname, o.lastname, os.name as status, o.date_added,o.shopper_id, o.total, o.currency_code, o.currency_value FROM `medrahoc_order` o LEFT JOIN medrahoc_order_status os ON (o.order_status_id = os.order_status_id) WHERE o.store_id = '0' AND o.order_status_id = '1' AND os.language_id = '1' AND ( o.shopper_id = NULL OR o.shopper_id = 0 ) ORDER BY o.order_id DESC

我的模型函数

public function getOrdersByStore($store_id, $status = null) {
            if (isset($status)) {
            $sql = "SELECT o.order_id, o.firstname, o.lastname, os.name as status, o.date_added,o.shopper_id as shopper_id  , o.total, o.currency_code, o.currency_value FROM  `" . DB_PREFIX . "order` o LEFT JOIN " . DB_PREFIX . "order_status os ON (o.order_status_id = os.order_status_id) WHERE  o.store_id = '" . (int) $store_id . "' AND o.order_status_id = '" . (int) $status . "' AND os.language_id = '" . (int) $this->config->get('config_language_id') . "' AND o.shopper_id = '0'  ORDER BY o.order_id DESC";
            } else {
                $sql = "SELECT o.order_id, o.firstname, o.lastname, os.name as status, o.date_added, o.total, o.currency_code, o.currency_value FROM  `" . DB_PREFIX . "order` o LEFT JOIN " . DB_PREFIX . "order_status os ON (o.order_status_id = os.order_status_id) WHERE o.store_id = '" . (int) $store_id . "' AND o.order_status_id > '0' AND os.language_id = '" . (int) $this->config->get('config_language_id') . "' ORDER BY o.order_id DESC";
            }
            $query = $this->db->query($sql);

            return $query->rows;
        }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题