我有一个 $_POST 数组,目前采用以下形式:
["Area"]=> array(2) {
[0]=> string(5) "Title"
[1]=> string(5) "Title"
}
["Issue"]=> array(2) {
[0]=> string(3) "111"
[1]=> string(7) "2222222"
}
["Elevation"]=> array(2) {
[0]=> string(8) "11111111"
[1]=> string(7) "2222222"
}
["Fix"]=> array(2) {
[0]=> string(8) "11111111"
[1]=> string(6) "222222"
}
["ExpectFee"]=> array(2) {
[0]=> string(8) "11111111"
[1]=> string(5) "22222"
}
["Outlay"]=> array(2) {
[0]=> string(9) "111111111"
[1]=> string(9) "222222222"
}
["ExpctTime"]=> array(2) {
[0]=> string(9) "111111111"
[1]=> string(11) "22222222222"
}
["Checkbox"]=> array(2) {
[0]=> string(12) "111111111111"
[1]=> string(11) "22222222222"
}
我目前正在像这样循环...
if ($_POST['OthProb']['Issue'] != '') {
$table = 'tbl_customproblems';
$kv = array();
foreach ($_POST['OthProb'] as $array) {
foreach ($array as $value) {
$kv[] = "'".$value."'";
}
$string = "INSERT INTO $table (AccountID, myID, Area, Issue, Elevation, Fix, ExpectFee, Outlay, ExpctTime, Checkbox) VALUES ('$_POST[AccountID]', '$_POST[myID]', ".join(", ", $kv).")";
}
} else {
$string = $_SERVER['QUERY_STRING'];
}
$sql = $DBH->prepare($string);
$sql->execute();
这几乎可以工作!它产生这个...
"INSERT INTO tbl_customproblems (AccountID, PropertyID, Area, Issue, Elevation, Fix, ExpectFee, Outlay, ExpctTime, WHCheckbox) VALUES ('81', '81', 'Title', 'Title', '111', '2222222', '11111111', '2222222', '11111111', '222222', '11111111', '22222', '111111111', '222222222', '111111111', '22222222222', '111111111111', '22222222222')"
如何修改循环以生成单独的插入,每行一个插入。