求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"]]
展开
 我来答
abccccaf
2017-11-04 · TA获得超过845个赞
知道小有建树答主
回答量:912
采纳率:86%
帮助的人:262万
展开全部

迭代时动态组装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();
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式