![]() |
Help w/ updating backend db with .csv file - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Help w/ updating backend db with .csv file (/showthread.php?tid=23437) |
Help w/ updating backend db with .csv file - El Forum - 10-11-2009 [eluser]puddles[/eluser] Hi, I'm a novice programmer, and need help. I've used the file uploading class from codeigniter to upload a hockey player statistics file, in .csv format. Now, I'd like to somehow read that file, parse it, and update a backend mysql db with each row of the data. I'm having trouble with some very basic things: 1) Understanding where the logic goes - in the view or in the controller? 2) What is the easiest way to take an array of a row's data (which has 31 fields), and insert it into a database using ActiveRecord? 3) Is there a way to add array items to each row so that I can supplement the data that was provided in the actual .csv file? Code: $row = 1; Any help or advice is greatly appreciated. Thank you. Help w/ updating backend db with .csv file - El Forum - 10-11-2009 [eluser]pistolPete[/eluser] [quote author="puddles" date="1255289050"]1) Understanding where the logic goes - in the view or in the controller?[/quote] Have a look at the user guide: http://ellislab.com/codeigniter/user-guide/overview/mvc.html There should be little to no logic in the view! [quote author="puddles" date="1255289050"]2) What is the easiest way to take an array of a row's data (which has 31 fields), and insert it into a database using ActiveRecord?[/quote] If the array is associative, it's as simple as Code: $this->db->insert($array); [quote author="puddles" date="1255289050"]3) Is there a way to add array items to each row so that I can supplement the data that was provided in the actual .csv file?[/quote] I don't know if I understood you correctly, but you can serialize an array and save the result to the database. http://php.net/manual/en/function.serialize.php |