2012-07-18 5 views
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 
    ) 
) 

지금 다음 만에 데이터베이스에 업데이트하려고 메신저 아무 소용 I 필드 만합니다 ([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 
} 

답변

3

이 너무 하위 배열 번호를 추가 좋은 것입니다.

if (is_array($values)) 
{ 
for ($i = 0; $i < count($values); $i++) 
{ 
    $item   = $values['item'][$i]; 
    $description = $values['description'][$i]; 
    $rate   = $values['rate'][$i]; 
    $id    = $values['itemid'][$i]; 

    // $query = "UPDATE `invoice_items` SET `item` = '{$item}', `description` = '{$description}', `rate` = '{$rate}' WHERE `id` = '{$id}';"; 
    // Setting query function here 
} 
+0

예, 그렇게해야합니다. 당신은 PHP의'foreach'도 사용할 수 있습니다. – Horen

+0

감사합니다. 매우 빠르게 반응합니다. 매우 인상 깊었습니다. – neoszion

+0

덕분에 저를 구해줍니다 :) :) – RayofHope

1

이와 비슷한?

if (is_array($values)) { 
    for ($i = 0; $i < count($values['itemid']); $i++) { 
     $item   = $values['item'][$i]; 
     $description = $values['description'][$i]; 
     $rate   = $values['rate'][$i]; 
     $id    = $values['itemid'][$i]; 

     $query = "UPDATE `invoice_items` SET `item` = '{$item}', `description` = '{$description}', `rate` = '{$rate}' WHERE `id` = '{$id}';"; 
     mysql_query($query); 
    } 
} 
관련 문제