Reputation: 417
I am uploading an excel file to upload all of its content into the mysql database, but I am stuck on how to insert the array into database.
I am now in this current position where I am showing the content of my array.
$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);
This is the result of the codes when I upload an excel file.
Array ( [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 number [L] => 9999999 [M] => CHUCK NORRIS [N] => BRUCE LEE [O] => AIRFORCE [P] => 1400 [Q] => 999 ) Array ( [A] => VISA [B] => RIZAL [C] => JOSE [D] => MANUAL [E] => KAPATIRAN [F] => MANILA [G] => 8888-ABCD-9999 [H] => 9.9998888777767E+15 [I] => 7777-DFGP-8888 [J] => 987654321 [K] => 200204 + GetGo number [L] => 888888 [M] => DONALD DUCK [N] => MICKEY MOUSE [O] => DISNEY [P] => 1600 [Q] => 888 )
My goal is to insert the A-Q of the array into A-Q of my table in database.
Upvotes: 0
Views: 345
Reputation: 417
I found out the answer to my question and I just want to share to hopefully help others in the future.
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);
}
Upvotes: 1