求php遍历数组插入mysql的代码。
我从HTML页面通过ajax发送了一个数组到PHP,求完整遍历数组插入mysql的代码谢谢。<?phpheader("Content-Type:text/html;cha...
我从HTML页面通过ajax发送了一个数组到PHP,求完整遍历数组插入mysql的代码谢谢。
<?php
header("Content-Type: text/html; charset=utf-8");
$shuju=$_POST["shuju"];
include("conn.php");
foreach ($shuju as &$value) {
}
?>
数据内容如下:
[["1","2017-10-19","11","22","33","44","55","wese","wew","wer","we","we"],["2","2017-10-20","66","77","88","99","1010","wr","w","w","rw","we"],["3","2017-10-21","211","222","233","244","255","311","322","333","344","355"],["4","2017-10-22","411","422","433","444","455","511","522","533","544","555"]]
[["1","2017-10-19","11","22","33","44","55","wese","wew","wer","we","we"],["2","2017-10-20","66","77","88","99","1010","wr","w","w","rw","we"],["3","2017-10-21","211","222","233","244","255","311","322","333","344","355"],["4","2017-10-22","411","422","433","444","455","511","522","533","544","555"]] 展开
<?php
header("Content-Type: text/html; charset=utf-8");
$shuju=$_POST["shuju"];
include("conn.php");
foreach ($shuju as &$value) {
}
?>
数据内容如下:
[["1","2017-10-19","11","22","33","44","55","wese","wew","wer","we","we"],["2","2017-10-20","66","77","88","99","1010","wr","w","w","rw","we"],["3","2017-10-21","211","222","233","244","255","311","322","333","344","355"],["4","2017-10-22","411","422","433","444","455","511","522","533","544","555"]]
[["1","2017-10-19","11","22","33","44","55","wese","wew","wer","we","we"],["2","2017-10-20","66","77","88","99","1010","wr","w","w","rw","we"],["3","2017-10-21","211","222","233","244","255","311","322","333","344","355"],["4","2017-10-22","411","422","433","444","455","511","522","533","544","555"]] 展开
展开全部
迭代时动态组装SQL语句去执行就可以:
$data = [
['name' => 'zs', 'addr' => 'china'],
['name' => 'ls', 'addr' => 'china'],
['name' => 'ww', 'addr' => 'china'],
];
foreach ($data as $value) {
$name = $value['name'];
$addr = $value['addr'];
$sql = "INSERT INTO tablename (name, addr) VALUES ('$name', '$addr')";
$message = add($sql) ? '插入成功' : '插入失败';
echo $message;
}
function add ($sql) {
mysql_query($sql);
return mysql_affected_rows();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询