恳请好心大佬帮忙修正以下$Arr部分的代码购物车页面
恳请好心大佬帮忙修正以下$Arr部分的代码
购物车页面
order.php 提交订单页面
$Arr = array($_POST['pid'],$_POST['amount']);
print_r($Arr);
/*现在打印出来的$Arr是这样的
Array (
[0] => Array (
[0] => 10
[1] => 13
[2] => 14
)
[1] => Array (
[0] => 5
[1] => 1
[2] => 2
)
)
*/
//导致下面的sql语句执行是insert into myorder (pid,amount) VALUES (10,13),(5,1);
/*******/
//上面要怎么修改才能变成下面这样的数组
//以及我想要的insert into myorder (pid,amount) VALUES (10,5),(13,1),(14,2);
/*
Array (
[0] => Array (
[0] => 10
[1] => 5
)
[1] => Array (
[0] => 13
[1] => 1
)
[2] => Array (
[0] => 14
[1] => 2
)
)*/
$sql = "insert into myorder (pid,amount VALUES ";
foreach ($Arr as $k => $v) {
$sql .= "(".$v[0].",".$v[1]."),";
}
$sql = substr($sql, 0,strlen($sql)-1);
mysql_query($sql,$conn);//$conn是数据库链接
?>
展开