我目前遇到Codigniter问题
这是我代码
public function move($data)
{
$sku = $data['sku'];
$store = $data['store_id'];
$sql = "SELECT * FROM products WHERE sku = ? AND store_id = ?";
$query = $this->db->query($sql, array($data['sku'], $data['store_id']));
if($query->result_array() != "") {
$data['qty'] = $data['qty'] + $query['qty'] ; //Error here
$insert = $this->db->query('products', $data);
return ($insert == true) ? true : false;
}
else{
}
}
在运行项目时出现此错误
Type: Error
Message: Cannot use object of type CI_DB_mysqli_result as array
Filename: C:\xampp\htdocs\index\stock\application\models\Model_products.php
我已经上网寻找解决方案,但我无法解决这个问题
谁能帮帮我?
3条答案
按热度按时间eimct9ow1#
您可能使用了错误的变量。请尝试以下操作:
wlwcrazw2#
$query-〉result_array()将从数据库中返回一个满足查询条件的行数组。如果你只需要一行,你必须修改它。
jqjz2hbq3#
在mysqli_result类中
这里主要使用两种类型
1.数组项集
1.单行
在使用mysqli_result类的格式中,有两种方法用于提取上述类别中的结果:
下面是PHP Codeigniter中的简单解决方案:-
我打电话给
1-示例”-
那就写"解决方案"
就像这样:-
问题已解决!