NIGEL COLLINS
NIGEL COLLINS

Reputation: 93

Opencart SQL error in your SQL syntax Error No. 1064

I am using the following query to select data from an Opencart DB. It all work fine until the final join where I am linking the product_to_category table, I then get the 1064 error. Without that join the query work fine - can anyone help please?

$purchased = "SELECT op.quantity, oo.product_option_value_id, oo.product_option_id,     op.order_product_id,op.product_id,op.name,o.order_id,ptc.product_id
                    FROM `order` o
                    JOIN `order_product` op ON o.order_id = op.order_id
                    LEFT JOIN `order_option` oo ON op.order_product_id =  oo.order_product_id
                    LEFT JOIN 'product_to_category' ptc ON  op.product_id = ptc.product_id";    

    if (!empty($data['filter_date_start'])) {
        $purchased .= " WHERE DATE(o.date_added) >= '" . $this->db- >escape($data['filter_date_start']) . "'";
    }   else {
        $purchased .= " WHERE DATE(o.date_added) >= '1900-01-01'";
    }
    if (!empty($data['filter_date_end'])) {
        $purchased .= " AND DATE(o.date_added) <= '" . $this->db->escape($data['filter_date_end']) . "'";
    }

Upvotes: 1

Views: 354

Answers (1)

Sankar V
Sankar V

Reputation: 4128

Change the single quotes around the last table name as below:

 $purchased = "SELECT op.quantity, oo.product_option_value_id, oo.product_option_id,     op.order_product_id,op.product_id,op.name,o.order_id,ptc.product_id
                FROM `order` o
                JOIN `order_product` op ON o.order_id = op.order_id
                LEFT JOIN `order_option` oo ON op.order_product_id =  oo.order_product_id
                LEFT JOIN `product_to_category` ptc ON  op.product_id = ptc.product_id";    

if (!empty($data['filter_date_start'])) {
    $purchased .= " WHERE DATE(o.date_added) >= '" . $this->db- >escape($data['filter_date_start']) . "'";
}   else {
    $purchased .= " WHERE DATE(o.date_added) >= '1900-01-01'";
}
if (!empty($data['filter_date_end'])) {
    $purchased .= " AND DATE(o.date_added) <= '" . $this->db->escape($data['filter_date_end']) . "'";
}

Have a nice day!!

Upvotes: 1

Related Questions