我正在使用 codeigniter 购物车库,我想从购物车中获取数据并通过隐藏字段将其传递给控制器以下是我的购物车数组
$cart = $this->cart->contents();
我在购物车中添加了三个项目,以下是 var_dump() 信息
array(3) { ["d3d9446802a44259755d38e6d163e820"]=> array(6) { ["rowid"]=> string(32) "d3d9446802a44259755d38e6d163e820" ["id"]=> string(2) "10" ["qty"]=> string(1) "1" ["price"]=> string(4) "1200" ["name"]=> string(11) "soup item 1" ["subtotal"]=> int(1200) } ["c51ce410c124a10e0db5e4b97fc2af39"]=> array(6) { ["rowid"]=> string(32) "c51ce410c124a10e0db5e4b97fc2af39" ["id"]=> string(2) "13" ["qty"]=> string(1) "1" ["price"]=> string(4) "1400" ["name"]=> string(11) "soup item 2" ["subtotal"]=> int(1400) } ["aab3238922bcc25a6f606eb525ffdc56"]=> array(6) { ["rowid"]=> string(32) "aab3238922bcc25a6f606eb525ffdc56" ["id"]=> string(2) "14" ["qty"]=> string(1) "1" ["price"]=> string(3) "800" ["name"]=> string(11) "soup item 3" ["subtotal"]=> int(800) } }
我从购物车中提取 id、name、qty 和 price 并插入隐藏字段,
<form action="http://localhost/food4u/site/order_now" method="post">
<input type="hidden" value="1" name="orderuserid">
<input type="hidden" value="1" name="order_restid">
<input type="hidden" value="238" name="orderDcharges">
<input type="hidden" value="578" name="ordergst">
<input type="hidden" value="3400" name="ordersubtotal">
<input type="hidden" value="1" name="orderPmethod">
<input type="hidden" value="10" name="cartitemid[]">
<input type="hidden" value="soup item 1" name="cartitemname[]">
<input type="hidden" value="1" name="cartitemqty[]">
<input type="hidden" value="1200" name="cartitemprice[]">
<input type="hidden" value="13" name="cartitemid[]">
<input type="hidden" value="soup item 2" name="cartitemname[]">
<input type="hidden" value="1" name="cartitemqty[]">
<input type="hidden" value="1400" name="cartitemprice[]">
<input type="hidden" value="14" name="cartitemid[]">
<input type="hidden" value="soup item 3" name="cartitemname[]">
<input type="hidden" value="1" name="cartitemqty[]">
<input type="hidden" value="800" name="cartitemprice[]">
--> 在我的控制器中,我得到了像这样的这些隐藏字段值
$cartitemid = $this->input->post('cartitemid');
$cartitemname = $this->input->post('cartitemname');
$cartitemqty = $this->input->post('cartitemqty');
$cartitemprice = $this->input->post('cartitemprice');
print_r($cartitemid).'<br />';
print_r($cartitemname).'<br />';
print_r($cartitemqty).'<br />';
print_r($cartitemprice).'<br />';
exit;
它会给我结果
Array ( [0] => 10 [1] => 13 [2] => 14 ) Array ( [0] => soup item 1 [1] => soup item 2 [2] => soup item 3 ) Array ( [0] => 1 [1] => 1 [2] => 1 ) Array ( [0] => 1200 [1] => 1400 [2] => 800 )
我只想在一张表中插入这个
$data = array(
'Iem_Id' => ???,
'Item_Name' => ???,
'Item_Qty' => ???,
'Item_Price' => ???,
);
我想将以上所有数据插入一张表中请指导我