我正在尝试在下一页中运行foreach循环,以获取codeigniter购物车库中的所有商品名称,价格和数量。但是我的foreach循环在以下页面中不起作用?请帮助。
<?php
$cdata = $this->cart->contents(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Website Payment Standard</title>
<script type="text/javascript" language="javascript">
function paypal_submit()
{
var actionName='https://www.sandbox.paypal.com/cgi-bin/webscr';
document.forms.frmOrderAutoSubmit.action=actionName;
document.forms.frmOrderAutoSubmit.submit();
}
</script>
</head>
<!--onload="paypal_submit();"-->
<body onload="paypal_submit();" >
<form style=" padding:0px;margin:0px;" name="frmOrderAutoSubmit" method="post" >
<input type="hidden" name="upload" value="1">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="sumon_goran@yahoo.com">
<?php foreach ($cdata as $v_cdata) { ?>
<input type="hidden" name="quantity" value="<?php echo $v_cdata['qty']; ?> " >
<input type="hidden" name="item_name" value="<?php echo $v_cdata['name']; ?> " >
<input type="hidden" name="amount" value="<?php echo $v_cdata['price']; ?> " >
<?php } ?>
<input type="hidden" name="rm" value="2" />
<input TYPE="hidden" name="address_override" value="0">
<input type="hidden" name="address1" value="<?php echo $billing_address;?>">
<input type="hidden" name="address2" value="<?php echo $shipping_info->address; ?>">
<input type="hidden" name="city" value="<?php echo $shipping_info->city; ?>">
<input type="hidden" name="zip" value="<?php echo $shipping_info->zip_code; ?>">
<input type="hidden" name="phone" value="<?php echo $shipping_info->phone; ?>">
</form>
</body>
</html>
答案 0 :(得分:0)
试试这个
<?php foreach ($cdata as $key=>$v_cdata) { ?>
<input type="hidden" name="quantity" value="<?php echo $v_cdata['qty']; ?> " >
<input type="hidden" name="item_name" value="<?php echo $v_cdata['name']; ?> " >
<input type="hidden" name="amount" value="<?php echo $v_cdata['price']; ?> " >
<?php } ?>
答案 1 :(得分:0)
如果您已经给出了数组,那么它应该可以工作。我已经用您给定的数据对其进行了测试。
你可以在这里看到现场演示:https://eval.in/88460
<?php
$cdata = array ( 'c4ca4238a0b923820dcc509a6f75849b' =>
array ( 'rowid' => 'c4ca4238a0b923820dcc509a6f75849b ','id' => 1 ,'qty' => 1, 'price' => 50000 ,'name' => 'Sony Xperia', 'subtotal' => 50000 ),
'c81e728d9d4c2f636f067f89cc14862c' =>
array ( 'rowid' => 'c81e728d9d4c2f636f067f89cc14862c', 'id' => '2', 'qty' => 1 ,'price' => 35000, 'name' => 'Samsung Galaxy', 'subtotal' => 35000 )
); ?>
<?php foreach ($cdata as $v_cdata) { ?>
<input type="hidden" name="quantity" value="<?php echo $v_cdata['qty']; ?> " >
<input type="hidden" name="item_name" value="<?php echo $v_cdata['name']; ?> " >
<input type="hidden" name="amount" value="<?php echo $v_cdata['price']; ?> " >
<?php } ?>
<强>输出:强>
<input type="hidden" name="quantity" value="1 " >
<input type="hidden" name="item_name" value="Sony Xperia " >
<input type="hidden" name="amount" value="50000 " >
<input type="hidden" name="quantity" value="1 " >
<input type="hidden" name="item_name" value="Samsung Galaxy " >
<input type="hidden" name="amount" value="35000 " >