Php 在多个mysql列中存储阵列

Php 在多个mysql列中存储阵列,php,mysql,arrays,forms,Php,Mysql,Arrays,Forms,我正在努力存储动态表单中的数据-在填充过程中可以添加/删除行 此表单的输出为数组: Array ( [service] => Array ( [0] => 1 [1] => 2 [2] => 3 ) [desc] => Array ( [0] => Complete service - description [1] => Half Service - description [2] => Break Service - description )

我正在努力存储动态表单中的数据-在填充过程中可以添加/删除行

此表单的输出为数组:

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>
表格定义:

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,但无法将其用于多个变量

多谢各位,
马丁

正如你所说,你必须用一个
来表示

 for($i=0;$i<count($values['service']);$i++)
 {
    $service = $values['service'][$i];
    $desc = $values['desc'][$i];
    $price = $values['price'][$i];

    //Now, perform the insert
 }

for($i=0;$i在您的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

}
$total=count($\u请求['price']);//获取总数
$arrService=$_请求['service'];//获取服务数组
$arrDesc=$_请求['desc'];//获取desc数组
$arrPrice=$_请求['price'];//获取价格数组

对于($i=0;$i这正是我所需要的。非常感谢!马丁尼,我也感谢你。我也在为请求的数量而挣扎。所以奥拉德的帮助帮助对我帮助更大。无论如何,谢谢你,奥斯卡。