-1

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'])
    );
}
Habib
  • 591
  • 8
  • 29
Upasana Chauhan
  • 948
  • 1
  • 11
  • 32
  • This line looks rather suspicious: `$combo_product_data[$result['quantity']] = $result['qty'];`. You use a different key for the same column. And it doesn't make much sense, shouldn't it be `$combo_product_data['quantity']`? – El_Vanja Apr 03 '20 at 17:47
  • But how will i get this in controller with bundle_id array – Upasana Chauhan Apr 03 '20 at 17:50
  • I am not getting results by using 'quantity' => $result['quantity'], in controller – Upasana Chauhan Apr 03 '20 at 17:53
  • You made a couple of mistakes and you really should be seeing errors. If you don't see them, enable [error reporting](https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display). And take the time to learn how to [debug your code](https://stackify.com/php-debugging-guide/). – El_Vanja Apr 03 '20 at 18:03
  • The desired format of the array you wish to return from `getcomboProduct` is unclear. Can you please include a sample of what it should look like in the question? – El_Vanja Apr 03 '20 at 18:18

1 Answers1

0

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."'");