Codeigniter Inserting Multidimensional Array as rows in MySQL

Posted by RisingSun on Stack Overflow See other posts from Stack Overflow or by RisingSun
Published on 2010-11-12T15:28:33Z Indexed on 2011/01/02 2:54 UTC
Read the original article Hit count: 222

Filed under:
|
|

Please Refer to this question I asked
Codeigniter Insert Multiple Rows in SQL

To restate

<tr>
<td><input type="text" name="user[0][name]" value=""></td>
<td><input type="text" name="user[0][address]" value=""><br></td>
<td><input type="text" name="user[0][age]" value=""></td>
<td><input type="text" name="user[0][email]" value=""></td>
</tr>
<tr>
<td><input type="text" name="user[1][name]" value=""></td>
<td><input type="text" name="user[1][address]" value=""><br></td>
<td><input type="text" name="user[1][age]" value=""></td>
<td><input type="text" name="user[1][email]" value=""></td>
</tr>
..........

Can Be Inserted into MySQL as this

 foreach($_POST['user'] as $user)
{
    $this->db->insert('mytable', $user);
}

This results in multiple MySQL queries. Is it possible to optimise it further, so that the insert occurs in one query

Something like this

insert multiple rows via a php array into mysql

but taking advantage of codeigniters simpler syntax. Thanks

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql