excel导入mysql的过程,已经获得到excel的数据内容$data,print_r之后是如下数据
$data=Array
(
[0] => Array
(
[0] => id
[1] => uid
[2] => order8
[3] => company
[4] => teamname
[5] => contacts
) [1] => Array
(
[0] =>
[1] => 2147483310
[2] => 1
[3] => 英才中学
[4] => 马到成功队
[5] => 张三
)
[2] => Array
(
[0] =>
[1] => 2147483320
[2] => 2
[3] => 第四十中学
[4] => 马马虎虎拿个冠军队
[5] => 刘莉
)
………………还有很多,共50条
[50] => Array
(
)
)请问如何才能将数组内容变成sql语句呢for语句 还是foreach 还是while,请大神给打个样吧
$data=Array
(
[0] => Array
(
[0] => id
[1] => uid
[2] => order8
[3] => company
[4] => teamname
[5] => contacts
) [1] => Array
(
[0] =>
[1] => 2147483310
[2] => 1
[3] => 英才中学
[4] => 马到成功队
[5] => 张三
)
[2] => Array
(
[0] =>
[1] => 2147483320
[2] => 2
[3] => 第四十中学
[4] => 马马虎虎拿个冠军队
[5] => 刘莉
)
………………还有很多,共50条
[50] => Array
(
)
)请问如何才能将数组内容变成sql语句呢for语句 还是foreach 还是while,请大神给打个样吧
sql='insert into biao values($value1,$value2,$value3)';
mysql_query($sql);
}}
$sql = 'INSERT INTO TABLE (field1, field2, field3 ....) VALUES ';
$i = 0;
foreach($items as $item){
if($i > 0) $sql .= ',';
$sql .= "( {$item['value1']}, {$item['value2']}, {$item['value3']} )"; $i++;
}#这样你插入100条只需要执行一次sql 连接一次数据库
#如果把sql执行放到循环中 100条数据将会请求100次数据库的连接 这是完全没有必要的mysql_query($sql);