How to import CSV file into database including mapping using Codeigniter

#1
[eluser]yagie[/eluser]
Can someone help me how to import CSV file into database including mapping using Codeigniter?

I don't know how. I'm looking for the example but I haven't found it.

Thanks..

#2
[eluser]Clooner[/eluser]
You could use fgetcsv to read the csv file and then run a foreach and insert each row using AR.

Code:
$data = fgetcsv($filehandle)
foreach ($data as $item)
   $this->db->insert('table', array('id' => $item[0], 'name' => $item[1]));

#3
[eluser]Clooner[/eluser]
Actually this is not how it works when I think about it. You'll be able to find how to use fgetcsv on php.net manuals!

#4
[eluser]yagie[/eluser]
Thanks Clooner for your replay. I used library for csv (csvreader). And then, I combined it with the code "foreach" you give and it works..


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.