开发者

submitting multiple rows to database with one form in codeigniter

开发者 https://www.devze.com 2023-01-18 06:55 出处:网络
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.

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.


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

}
0

精彩评论

暂无评论...
验证码 换一张
取 消