CodeIgniter Forums
How to Insert auto multiple row in database - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12)
+--- Thread: How to Insert auto multiple row in database (/showthread.php?tid=66968)



How to Insert auto multiple row in database - kabirhossain - 12-25-2016

Please would you help me  How to Insert auto multiple row in database?
have tried but fail .
 


RE: How to Insert auto multiple row in database - enlivenapp - 12-26-2016

Perhaps if you try explaining (in much more detail) what you're trying to do, we can help.


RE: How to Insert auto multiple row in database - PaulD - 12-26-2016

PHP Code:
$data = array(
        array(
                
'title' => 'My title',
                
'name' => 'My Name',
                
'date' => 'My date'
        
),
        array(
                
'title' => 'Another title',
                
'name' => 'Another Name',
                
'date' => 'Another date'
        
)
);

$this->db->insert_batch('mytable'$data); 

Above from the docs.
https://www.codeigniter.com/user_guide/database/query_builder.html#inserting-data
(You have to scroll down a bit to the end of that section).

1. Get your data together however you want (from a form input, from a curl, from an admin screen etc)
2. Create your multi dimensional array.
3. Use update_batch to insert multiple rows.

Easy peasy. Lightweight. Fast. Powerful. Flexible. As most things CI are :-)

Hope that helps.

Paul.

PS You would get a more specific answer if you posted what you had "tried and failed". (What did you try? What did you expect? What did you get?)