【4个数组同时写到数据库怎么写?】
$_post['a'] 值为1,2,3,4,5
$_post['b'] 值为a,b,c,d,e
$_post['c'] 值为男,女,女,男,男
$_post['d'] 值为25,26,27,26,26
这四个数组同时是从里接收过来的。现在我要把它们都写入到数据库里,循环应该怎么写?
最后写到数据库的格式应该是
编号 姓名 性别 年龄
第一条:1 a 男 25
第二条:2 b 女 26
第三条:3 c 女 27
第四条:4 d 男 26
第五条:5 e 男 26
------解决方案--------------------
$_post['a'] = '1,2,3,4,5';
$_post['b'] = a,b,c,d,e;
$_post['c'] = 男,女,女,男,男;
$_post['d'] = 25,26,27,26,26;
$a = explode(',', $_post['a']);
$b = explode(',', $_post['b']);
$c = explode(',', $_post['c']);
$d = explode(',', $_post['d']);
foreach($a as $key=>$value){
$sql = inser into tbl_name values('$value', '{$b[$key]}', '{$c[$key]}', '{$d[$key]}');;
//mysql_query($sql);
echo $sql, php_eol;