2
我一直在絞盡腦汁想出這幾天的結果,並且總結出來了。我想用下面的表單值來更新數據庫中的行:每次更新到mysql的html表格數組
<input type="text" name="item[]" maxlength="255" value="',htmlentities($item["item"]),'">
<input type="text" name="description[]" maxlength="255" value="',htmlentities($item["description"]),'">
<input type="text" name="rate[]" maxlength="10" value="',htmlentities($item["rate"]),'">
<input type="hidden" name="itemid[]" value="',htmlentities($item["id"]),'" />
這下面的數組回:
Array
(
[item] => Array
(
[0] => item listing 1
[1] => item listing 2
)
[description] => Array
(
[0] => item testing description
[1] => item testing description
)
[rate] => Array
(
[0] => 1.00
[1] => 2.00
)
[itemid] => Array
(
[0] => 1
[1] => 2
)
)
現在我試着用下面的,但更新到數據庫無濟於事我只能更新字段([1]值)的最後一行:(任何幫助將是巨大的
if (is_array($values))
{
for ($i = 0; $i < count($values); $i++)
{
$item = $values['item'];
$description = $values['description'];
$rate = $values['rate'];
$id = $values['itemid'];
// $query = "UPDATE `invoice_items` SET `item` = '{$item}', `description` = '{$description}', `rate` = '{$rate}' WHERE `id` = '{$id}';";
// Setting query function here
}
是的,應該這樣做。你可以使用PHP的'foreach'以及 – Horen 2012-07-18 16:41:52
感謝像魅力一樣...非常快速的迴應,非常令人印象深刻。 – neoszion 2012-07-18 16:54:48
謝謝它節省了我:) :) :) – RayofHope 2013-02-21 10:40:42