简体   繁体   中英

getting null value while passing varaible from model to controller in php

getting null value while passing a variable from model to controller in PHP with the following code. Actually I am not able to pass the quantity from model to controller.

model ->

public function getcomboProduct ($product_id) {
    $combo_product_data = array();
    $query = $this->db->query("Select bundled_id,qty FROM " . DB_PREFIX . "product_bundle where 
 product_id=" . $product_id . "");
    foreach ($query->rows as $result) {
        $combo_product_data[$result['bundled_id']] = $this->getProduct($result['bundled_id']);

        $combo_product_data[$result['quantity']] = $result['qty'];

    }

    return $combo_product_data;
}

controller ->

$results = $this->model_catalog_product->getcomboProduct($product_id);

foreach ($results as $result) {

    $data['comboproducts'][] = array(
        'product_id' => $result['product_id'],
        'thumb'      => $image,
        'quantity'   => $result['quantity'],
        'name'       => $result['name'],
        'price'      => $price,
        'href'       => $this->url->link('product/product', 'product_id=' . $result['product_id'])
    );
}

I think you made syntax error in sql query, so you need to place ".$product_id." into single quotation like '".$product_id."' as follows

$query=$this->db->query("Select bundled_id,qty FROM " . DB_PREFIX ."product_bundle where product_id='".$product_id."'");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM