私はこれを何日も理解しようと頭を悩ませてきましたが、足りませんでした。次のフォーム値でデータベースの行を更新しようとしています。
<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
}