我想将数组值写入我的数据库,例如:
“更新 tbl SET $fieldname = $fieldvalue WHERE id=$recid”
我从以下位置得到这个数组$_POST['changed']
:
[changed] => Array
(
[0] => Array
(
[recid] => 1
[vorname] => Walter
[nachname] => Bauer
)
[1] => Array
(
[recid] => 2
[vorname] => Michael
)
[2] => Array
(
[recid] => 3
[vorname] => Peter
[nachname] => Highler
[email] => p.highler@aol.com
)
[3] => Array
(
[recid] => 4
[vorname] => Maria
[nachname] => Maier
)
[4] => Array
(
[recid] => 5
[vorname] => Werner
[nachname] => Rock
)
)
当我使用此foreach
循环执行此操作时,recid
get 也作为字段名称 - 但这不应该发生。
foreach ($_POST['changed'] as $SubArray)
{
foreach ($SubArray as $key => $value)
{
$sql .= "UPDATE kunden SET ".$key."='".$value."' WHERE id=**?????????**";
}
}