2

我有这个表格,当您单击“新行”时,会弹出另一个带有新输入的字段。我想用这个实现的是一个用户友好的表单,它 FOREACH "New item" ->

("INSERT 
INTO menues(
    restaurant_id,
    title, 
    subtitle, 
    name, 
    ingredients, 
    price, 
    category, 
    upload_date
    )
VALUES(
    :restaurant_id,
    :title, 
    :subtitle, 
    :name, 
    :ingredients, 
    :price, 
    :category,
    NOW()
    )
");

添加多行时,每行应具有相同的值,从表单的上部字段(标题,副标题)+ restaurant_id 和类别BUT名称、成分和价格的值不同。

我可以通过什么方式实现这一目标?

表格:

点击之前 单击“新行”时>> 点击后

4

2 回答 2

3

你可以让你的输入字段返回一个数组:

<input type="text" name="food_name[]" />
<input type="text" name="food_ingredient[]" />
<input type="text" name="food_price[]" />

然后遍历结果:

$name = $_POST["food_name"];
$ingredient = $_POST["food_ingredient"];
$price = $_POST["food_price"];
$length = count($name);
for($key=0;$key<$length;$key++){
 echo $name[$key] . "<br/>"; 
 echo $ingredient[$key] . "<br/>"; 
 echo $price[$key] . "<br/>";  
 echo "-----<br/>";
} 

当我遇到你的问题时,我就是这样做的。

于 2013-05-27T17:36:36.840 回答
0

这是我认为的一个php问题。将表单中的值读入数组。然后运行另一个代码块,使用 for each 构造将数组插入到表中,并使用 sql 语句将数组的元素迭代地插入到表中,直到数组用完。

于 2013-05-27T17:12:03.500 回答