我将一个数组传递给一个查询。但是,我似乎无法添加每个值`。
我传递的数组是:
Array (
[name] => Name
[address_1] => Address 1
[address_2] => Address 2
[address_3] => Address 3
[address_4] => Address 4
[post_code] => Post COde
[proptype] => rent
[style] => house
[beds] => 1
[bathrooms] => 1
[garden] => 1
[furnished] => yes
[deposit] => Deposit
[available] => 10/18/2013
[description] => Description
)
下面是我的代码:
foreach ($data as $column => $value) {
$columns .= ($columns == "") ? "" : ", ";
$columns .= $column;
$values .= ($values == "") ? "" : ", ";
$values .= $value;
}
$sql = "INSERT INTO $table ($columns) VALUES ($values)";
echo "--->" . $sql;
exit;
我知道我需要包含每个值,但我看不到我需要在哪里执行此操作。
谢谢你的时间。