views:

44

answers:

1

Hi,

I'm trying to create a bulk edit page for an app that I'm working on. The table contains rows of products each of which have three editable fields.

<tr>
  <input type="hidden" name="id" value="10">
  <td>SKU<td>
  <td>Product Name</td>
  <td>
    <select name="product_category" value="" tabindex="4">
      <option value="1">Category 1</option>
      <option value="2">Category 2</option>
    </select>
  </td>
  <td><input type="text" name="current_inventory" class="short" value="15"  tabindex="5"></td>
  <td><input type="text" name="inventory_alert" class="short" value="6" id="inventory_alert" tabindex="6"></td>
</tr>

Every row can be edited and there is one submit button on the page. How should I format this correctly so that I can update each entry in the database with the values? Thanks.

+1  A: 

you can use arrays as form names with php

<input type="text" name="product[current_inventory]" class="short" value="15"  tabindex="5">
...

when you process the form you can use

foreach( $_POST['product'] as $product ) {

    $current_inventory = $product['current_inventory'];
    // sql statement to update product

}
Galen
this makes sense but when i print the array it only contains the last row in the table. I feel like I'm missing something small.
Brian Hayes