数据组循环入库

Aa291121289 2018-01-22 11:55:19
pid,uid一样,把下面变量以|分割后一组一组的入库
比如第一组数据:1,2,1996年,1月,2002年,9月,实验中学,计算机,初中,1
比如第二组数据:1,2,2002年,1月,2005年,9月,路桥中学,计算机,高中,2
比如第三组数据:1,2,2005年,3月,2008年,9月,浙江工业大学,工商贸易,大专,3
......

有几组入库几组
$pid=1;
$uid=2;
$jystartyear='1996年|2002年|2005年';
$ajystartyear = array();
$ajystartyear = explode('|',$jystartyear);

$jystartmonth='1月|1月|3月';
$aystartmonth = array();
$aystartmonth = explode('|',$jystartmonth);

$jyendyear='2002年|2005年|2008年';
$ajyendyear = array();
$ajyendyear = explode('|',$jyendyear);

$jyendmonth='9月|9月|9月';
$ajyendmonth = array();
$ajyendmonth = explode('|',$jyendmonth);

$jyschool='实验中学|路桥中学|浙江工业大学';
$ajyschool = array();
$ajyschool = explode('|',$jyschool);

$jyspeciality='计算机|计算机|工商贸易';
$ajyspeciality = array();
$ajyspeciality = explode('|',$jyspeciality);

$jyeducation='初中|高中|大专';
$ajyeducation = array();
$ajyeducation = explode('|',$jyeducation);

$jyeducation_id='1|2|3';
$ajyeducation_id = array();
$ajyeducation_id = explode('|',$jyeducation_id);



$sql = "insert into resume_education (pid,uid,startyear,startmonth,endyear,endmonth,school,speciality,education,education_cn) values('$pid','$uid','?','?','?','?','?','?','?','?')";


已经把变量分割成数组,请问下怎么循环入库,麻烦知道的大哥直接给下代码,谢谢了,小弟是菜鸟
...全文
196 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_34139573 2018-01-22
  • 打赏
  • 举报
回复
$num = 3;//待插入的记录数量
for($i=0;$i<$num;$i++){    
    $sql = "insert into resume_education (pid,uid,startyear,startmonth,endyear,endmonth,school,speciality,education,education_cn) values('$pid','$uid','{$ajystartyear[$i]}','{$aystartmonth[$i]}','$ajyendyear[$i]}','{$ajyendmonth[$i]}','{$ajyschool[$i]}','{$ajyspeciality[$i]}','{$ajyeducation[$i]}','{$ajyeducation_id[$i]}')";

    //执行sql语句
}
Aa291121289 2018-01-22
  • 打赏
  • 举报
回复
有没大哥帮忙看看呢,麻烦了,谢谢了

21,891

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧