【发布时间】:2014-07-21 18:28:03
【问题描述】:
我有一个使用 jquery 动态创建的表。现在我将输入(当然是数组)发送到数据库。这些字段是customCLASSE[]、customQTY[]、customPRICE[]...这是我在 MySQL 中插入数据的脚本:
if ($_POST['customCLASSE']) {
foreach ( $_POST['customCLASSE'] as $key=>$value ) {
$query = $mysqli->query("INSERT INTO booking_multiday_detail (classe) VALUES ('$value')");
}
}
效果很好,但我的问题是:如何在插入 customCLASSE 的同时在同一个 foreach 中插入其他输入(customQTY[]、customPRICE[]...)?
【问题讨论】:
-
你不能对多个数组使用一个 foreach .. 尝试使用 'for' 方式然后(设置一个迭代器变量并迭代它).. 也使用 sql multi insert(在其中插入多行单个查询)