2010-09-29 120 views
1

我正在尝试为正在处理的应用程序创建一个批量编辑页面。该表包含各有三个可编辑字段的产品行。用codeigniter中的一个表单向数据库提交多行

<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> 

每一行都可以进行编辑,并有一个提交页面上的按钮。我应该如何正确格式化,以便可以使用值更新数据库中的每个条目?谢谢。

回答

2

你可以使用数组作为表单名称与PHP

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

当你处理表单,您可以使用

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

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

} 
+0

这是有道理的,但是当我打印数组仅包含在最后一排桌子。我觉得我错过了一些小事。 – 2010-09-30 01:41:07

+0

是的,你需要更新数组。如果你需要像我一样拥有一个数组数组(更像是一个数据库结果集,一个行数组是字段数组),那么试试:'name =“product [i] [current_inventory]”'并增加我为每一行。 – ise 2012-04-09 14:13:06

相关问题