Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php中将变量从模型传递到控制器时获取null值_Php_Mysql - Fatal编程技术网

在php中将变量从模型传递到控制器时获取null值

在php中将变量从模型传递到控制器时获取null值,php,mysql,Php,Mysql,使用以下代码在PHP中将变量从模型传递到控制器时获取null值。实际上,我无法将数量从模型传递到控制器 型号-> public function getcomboProduct ($product_id) { $combo_product_data = array(); $query = $this->db->query("Select bundled_id,qty FROM " . DB_PREFIX . "product_bundle where produc

使用以下代码在PHP中将变量从模型传递到控制器时获取null值。实际上,我无法将数量从模型传递到控制器

型号->

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;
}
控制器->

$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'])
    );
}

我认为您在sql查询中犯了语法错误,所以您需要将“$product\U id.”放在单个引号中,如“.$product\U id.”中,如下所示

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

这一行看起来相当可疑:
$combo_product_data[$result['quantity']]=$result['quantity']。对同一列使用不同的键。这没有多大意义,是不是应该是
$combo\u product\u data['quantity']
?但是我如何在具有bundle\u id阵列的控制器中获得它?我使用'quantity'=>$result['quantity']并没有得到结果,在控制器中您犯了几个错误,您真的应该看到错误。如果看不到它们,请启用。并花时间学习如何使用。您希望从
getcomboProduct
返回的数组的所需格式尚不清楚。您能在问题中包含一个它应该是什么样子的示例吗?只有当
product\u id
是字符串时,这才是正确的,如果它是数值,则不需要引号。