你好,一个多行记录的表单,插入数据库的代码怎么写啊?希望能指点一下,谢谢
Array([name]=>Array([0]=>小米[1]=>黄豆[2]=>红豆)[spe]=>Array([0]=>袋[1]=>袋[2]=>袋)[price]=>Ar...
Array
(
[name] => Array
(
[0] => 小米
[1] => 黄豆
[2] => 红豆
)
[spe] => Array
(
[0] => 袋
[1] => 袋
[2] => 袋
)
[price] => Array
(
[0] => 3
[1] => 5
[2] => 5
)
[total] => Array
(
[0] => 4
[1] => 2
[2] => 3
)
[aom] => Array
(
[0] => 12
[1] => 10
[2] => 15
)
[note] => Array
(
[0] => 试
[1] => 试1
[2] => 没事
)
) 展开
(
[name] => Array
(
[0] => 小米
[1] => 黄豆
[2] => 红豆
)
[spe] => Array
(
[0] => 袋
[1] => 袋
[2] => 袋
)
[price] => Array
(
[0] => 3
[1] => 5
[2] => 5
)
[total] => Array
(
[0] => 4
[1] => 2
[2] => 3
)
[aom] => Array
(
[0] => 12
[1] => 10
[2] => 15
)
[note] => Array
(
[0] => 试
[1] => 试1
[2] => 没事
)
) 展开
1个回答
展开全部
最后的语句要做成这个样子:
INSERT INTO tab(f1,f2,...) VALUES (...),(....),(...)
要把数组 $p 做成这个样子的字符串 $sql ,可以用下面的循环:
$sql='INSERT INTO tab(f1,f2,...) VALUES ';
$vstr='';
for ($i=0;$i<count($p['name']);$i++){
$vstr='("'.$p['name'].'","'.$p['size'].'",...';
}
$sql.=substr($vstr,0,length($vstr)-1);//删除末尾的逗号
来自:求助得到的回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询