0

所以在这里我为 OpenCart 编写这个自定义模块,我收到以下错误:

SELECT p.upc AS product_upc, TRIM(ma.make) AS make, IFNULL(TRIM(mo.model), 0)
AS model, p2y.begin_year, p2y.end_year, IFNULL(TRIM(en.engine), 0) AS engine, 
IFNULL(TRIM(si.size), 0) AS size FROM product_to_car p2y LEFT JOIN product p ON 
p.product_id = p2y.product_id LEFT JOIN make ma ON ma.id = p2y.make_id LEFT JOIN
model mo ON mo.id = p2y.model_id LEFT JOIN `size si ON si.id = p2y.size_id`engine
en ON en.id = p2y.engine_id ORDER by ma.make, mo.model, si.size, en.engine,
p2y.begin_year in C:\wamp\www\NewDev\system\database\mysql.php on line 50

该错误的代码如下:

public function download($uid = 'product_id'){
    if($uid == 'product_id') {
        $query = $this->db->query("SELECT p2y.product_id, TRIM(ma.make) AS make, IFNULL(TRIM(mo.model), 0) AS model, p2y.begin_year, p2y.end_year, IFNULL(TRIM(en.engine), 0) AS engine, IFNULL(TRIM(si.size), 0) AS size FROM " . DB_PREFIX . "product_to_car p2y LEFT JOIN " . DB_PREFIX . "make ma ON ma.id = p2y.make_id LEFT JOIN " . DB_PREFIX . "model mo ON mo.id = p2y.model_id LEFT JOIN `" . DB_PREFIX . "size` si ON si.id = p2y.size_id`" . DB_PREFIX . "engine` en ON en.id = p2y.engine_id ORDER by ma.make, mo.model, si.size, en.engine, p2y.begin_year");
    } else {
        switch($uid) {
            case 'model':
                $identifier = 'p.model AS product_model';
                break;
            case 'sku':
                $identifier = 'p.sku AS product_sku';
                break;
            case 'upc':
                $identifier = 'p.upc AS product_upc';
                break;
            case 'ean':
                $identifier = 'p.ean AS product_ean';
                break;
            case 'mpn':
                $identifier = 'p.mpn as product_mpn';
                break;
            case 'isbn':
                $identifier = 'p.isbn AS product_isbn';
                break;
            default:
                $identifier = 'p2y.product_id';
                break;
        }
        $query = $this->db->query("SELECT " . $identifier . ", TRIM(ma.make) AS make, IFNULL(TRIM(mo.model), 0) AS model, p2y.begin_year, p2y.end_year, IFNULL(TRIM(en.engine), 0) AS engine, IFNULL(TRIM(si.size), 0) AS size FROM " . DB_PREFIX . "product_to_car p2y LEFT JOIN " . DB_PREFIX . "product p ON p.product_id = p2y.product_id LEFT JOIN " . DB_PREFIX . "make ma ON ma.id = p2y.make_id LEFT JOIN " . DB_PREFIX . "model mo ON mo.id = p2y.model_id LEFT JOIN `" . DB_PREFIX . "size si ON si.id = p2y.size_id`" . DB_PREFIX . "engine en ON en.id = p2y.engine_id ORDER by ma.make, mo.model, si.size, en.engine, p2y.begin_year");
    }

我已经重写了好几次,它仍然无法正常工作。如果我删除这个`" .DB_PREFIX. "size si ON si.id = p2y.size_id“它工作正常。

我也需要让它size工作。

关于可能导致此错误的任何线索?

4

1 回答 1

1

您在第二次 LEFT JOIN 中错过了一些反引号

LEFT JOIN `" . DB_PREFIX . "size si ON si.id = p2y.size_id`" . DB_PREFIX . "engine en ON en.id = p2y.engine_id

应该

LEFT JOIN `" . DB_PREFIX . "size` si ON si.id = p2y.size_id, `" . DB_PREFIX . "engine` en ON en.id = p2y.engine_id
                                ^                          ^^^                       ^
于 2013-10-24T21:35:40.857 回答