CodeIgniter Forums
Adding an array to a DB - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Adding an array to a DB (/thread-2445.html)



Adding an array to a DB - El Forum - 08-06-2007

[eluser]eedfwChris[/eluser]
I thought there was a function in the database library but I can't for the life of me find the function.

My array looks like this...
Code:
Array (
    [0] => Array
        (
            [name] => COMPANY_NM
            [csv_company_id] => MATCH_CID
        )
)

Each nested array is a row with columns named the same as in the database.

Thanks!


Adding an array to a DB - El Forum - 08-06-2007

[eluser]Michael Wales[/eluser]
Well - we'll first have to iterate through your top-level array, then we can use the Active Record insert function to insert the arrays found within your top-level array.

Code:
foreach ($top_level as $child) {
  $this->db->insert('table', $child);
}