$_POST['pid'] = array(
10,
13,
14,
);
$_POST['amount'] = array (
5,
1,
2,
);
$sql = "insert into myorder (pid,amount) VALUES";
foreach ($_POST['pid'] as $key => $pid) {
$amount = $_POST['amount'][$key];
$sql .= "({$pid}, {$amount}),";
}
$sql = trim($sql, ',');
echo $sql;
?>
试试这段代码,最后输出的sql就是:
insert into myorder (pid,amount) VALUES(10, 5),(13, 1),(14, 2)