CodeIgniter Forums
multiple insert - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: multiple insert (/thread-37504.html)



multiple insert - El Forum - 01-11-2011

[eluser]zawaruddin[/eluser]
i have read the CI user guide for insert_string. And this is the code :

$data = array('name' => $name, 'email' => $email, 'url' => $url);
$str = $this->db->insert_string('table_name', $data);

but in my case, i've data in array
$data = array('name' => array('zawaruddin','devi','farhan'),
'email' => array('[email protected]','[email protected]','[email protected]'),
'url' => array('url1','url2','url3'));

$str = $this->db->insert_string('table_name', $data);

can i insert $data in db with insert_string function??? or other insert function???
my dbms is postgre...

thanks


multiple insert - El Forum - 01-11-2011

[eluser]Atharva[/eluser]
You need a loop,something like
Code:
for($i=0;$i<3;$i++){
$insert = array(‘name’ =>  $data['name'][$i], ‘email’ => $data['email'][$i], ‘url’ => $data['url'][$i]);
$str = $this->db->insert_string(‘table_name’, $insert);
}//for

Though you should dynamically determine the value of $i (in this case taken as 3)