我很难从动态表单中存储数据 - 可以在填充行时添加/删除行。
此表单的输出是数组:
Array ( [service] => Array ( [0] => 1 [1] => 2 [2] => 3 ) [desc] => Array ( [0] => Complete service - description [1] => Half Service - description [2] => Break Service - description ) [price] => Array ( [0] => 1000 [1] => 500 [2] => 800 ) [income_sum] => 2300 [odeslat] => Odeslat )
表定义:
Column Type Comment
id int(11) Auto Increment
order_id int(11) NULL
servis_id tinyint(4) NULL
price int(11) NULL
desc text NULL
表格定义:
<form action="test.php" method="get" id="form">
<div class='container'>
<select name='service[]'>
<option value=""></option>
<option value="1">Complete Service</option>
<option value="2">Half Service</option>
<option value="3">Break Service</option>
</select>
Description
<input type='text' name='desc[]'>
Price
<input class='income_count' type='text' name='price[]'>
<input type="submit">
</form>
我不知道如何存储这些具有多个值的多列。 我会使用 FOREACH,但未能将其与多个变量一起使用。
非常感谢, 马丁
最佳答案
在你的 test.php 中获取一个计数来检查你有多少表单数据集并循环遍历它:
$total = count($_REQUEST['price']); // get total
$arrService = $_REQUEST['service'];// get services array
$arrDesc = $_REQUEST['desc']; //get desc array
$arrPrice = $_REQUEST['price']; // get price array
for($i=0;$i<$total;$i++){
$service = $arrService[$i];
$dsc = $arrDesc[$i];
$price = $arrPrice[$i];
//insert those data into database
}
关于php - 将数组存储在多个mysql列中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22862460/