【发布时间】:2020-05-04 01:45:00
【问题描述】:
我试图在我的模型中将数据从一个表移动到另一个表。在前两行中,我得到了“购物车”表中与用户名匹配的所有行。我现在正在尝试遍历所有这些并将产品 ID 与我的“产品”表中的产品 ID 匹配。然后我尝试格式化数据以适合我的名为“已售”的新表。但是我收到一个错误。我认为 $q->id、$q->product_name 等的语法是错误的。我知道您通常可以在视图中使用它,但它在模型中不起作用。你知道这样做的正确语法是什么吗?
function checkout($username){
$this->db->where('username', $username);
$query = $this->db->get('cart');
//$data = array();
foreach ($query as $q){
$product = $this->db->get_where('product', array('id' => $q->id));
$arr['product_id'] = $product->id;
$arr['product_brand'] = $product->item_brand;
$arr['product_name'] = $product->item_name;
$arr['product_image'] = $product->item_image_url;
$arr['product_price'] = $product->item_price;
$arr['product_size'] = $product->item_size;
$arr['name_of_seller'] = $product->name_of_lister;
$arr['name_of_buyer'] = $this->session->userdata('username');
$this->db->insert('sold', $arr);
}
//Deletes the items out of the cart
// $this->db->delete('cart');
}
这是我收到的错误消息
【问题讨论】:
-
您好,欢迎您,当您想显示一些非常重要的信息(例如收到的错误消息)时,最好避免在问题中使用图片。图片不能被搜索引擎索引。
标签: php sql codeigniter