我正在上传一个excel文件,将其所有内容上传到mysql数据库,但我仍然坚持如何将数组插入数据库。
我现在处于显示阵列内容的当前位置。
$data['values'] = $arr_data; //this is the last line from my controller where I extracted the excel file
$sql = "truncate TABLE master_list;";
$query = $this->db->query($sql);
$sql = array();
foreach( $data as $row )
print_r($row);
这是我上传excel文件时代码的结果。
阵列([A] => MASTER CARD [B] => CHUA [C] => JOHN CHRISTOPER [D] => VELUZ [E] => UNIONBANK [F] => ORTIGAS [G] => 1234-ABCD-5678 [H] => 1.6161616161616E + 15 [I] => 8765-EFGH-4321 [J] => 123456789 [K] => 200203+ GetGo号码[L] => 9999999 [M] => CHUCK NORRIS [N] => BRUCE LEE [O] => AIRFORCE [P] => 1400 [Q] => 999)数组([A] => VISA [B] => RIZAL [C] => JOSE [D] =>手动[E] => KAPATIRAN [F] =>马尼拉[G] => 8888-ABCD-9999 [H] => 9.9998888777767E + 15 [I] => 7777-DFGP-8888 [J] => 987654321 [K] => 200204 + GetGo号码[L] => 888888 [M] => DONALD DUCK [N] => MICKEY MOUSE [O] =>迪士尼[P] => 1600 [Q] => 888)
我的目标是将数组的A-Q插入数据库中我的表的A-Q中。
答案 0 :(得分:0)
我找到了问题的答案,我只想分享,希望将来可以帮助其他人。
foreach($data['values'] as $row){
//echo $row['A'];
$sql = "insert into sampleTable(dasdasda,dadasda)values('".$row['A'] . "','" . $row['B'] . "')";
echo $sql;
$this->db->query($sql);
}