把数组变成字符串:比如$a=array{"12","23","34","45"}
$a="12,23,34,45"把这个存到数据库中就行了
读取时再用explode变成数组
如果你的array不需要处理,直接就可以insert into
例如:
INSERTINTO db1_name (field1,field2) SELECT field1,field2 FROM db2_name
这种格式不能加values
<?php
$_POST['pid'] = array(
10,
13,
14,
)
$_POST['amount'] = array (
5,
1,
2,
)
$sql = "insert into myorder (pid,amount) VALUES"
foreach ($_POST['pid'] as $key => $pid) {
$amount = $_POST['amount'][$key]
$sql .= "({$pid}, {$amount}),"
}
$sql = trim($sql, ',')
echo $sql
?>
试试这段代码,最后输出的sql就是:
insert into myorder (pid,amount) VALUES(10, 5),(13, 1),(14, 2)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)