Php 处理为一行插入的多个字段
我有一个表单如下所示:Php 处理为一行插入的多个字段,php,html,mysql,codeigniter,Php,Html,Mysql,Codeigniter,我有一个表单如下所示: <form method='post' action='post.php'> <span> <input type='text' name='ingredientQTY'/> <select name='selectTYPE'> <option value='1' name='1'>BLAH</option> <option valu
<form method='post' action='post.php'>
<span>
<input type='text' name='ingredientQTY'/>
<select name='selectTYPE'>
<option value='1' name='1'>BLAH</option>
<option value='2' name='2'>BLAH2</option>
<option value='2' name='3'>BLAH3</option>
</select>
<input type='text' name='ingredientNAME'/>
</span>
</form>
废话
废话
废话
我在一侧有一个脚本,可以克隆跨距并将克隆添加到页面中,因此我可以拥有n如上所述的跨距数。我有一个名为配料的数据库,看起来像这样:
<form method='post' action='post.php'>
<span>
<input type='text' name='ingredientQTY'/>
<select name='selectTYPE'>
<option value='1' name='1'>BLAH</option>
<option value='2' name='2'>BLAH2</option>
<option value='2' name='3'>BLAH3</option>
</select>
<input type='text' name='ingredientNAME'/>
</span>
</form>
第1行:ingredientQTY——由跨度中的第一个输入填充
第2行:ingredientTYPE——由跨度中选择/下拉列表的值填充
第3行:ingredientNAME——由跨度中的最后一个输入填充
因此,每个跨度的字段在单个表行中更新1列。但是我可以有n需要插入的行数,对应于通过jQuery添加的跨距数
我如何用PHP构建它?我正在寻找一个更具概念性的答案(我不是说有人来构建它),但示例会很好
谢谢大家的帮助,如果这个问题让人困惑,尽管问吧 如果使用PHP处理表单,可以创建如下字段名:
或
这些名称可以循环,如下所示:
foreach($_POST['ingredientQTY'] as $key => $value) {
$qty = $_POST['ingredientQTY'][$key]; // or $value
$type = $_POST['selectTYPE'][$key];
$name = $_POST['ingredientNAME'][$key];
}
我想这就是你的意思