![]() |
How to insert multiple rows from a single view. - 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: How to insert multiple rows from a single view. (/showthread.php?tid=44196) |
How to insert multiple rows from a single view. - El Forum - 08-06-2011 [eluser]FlingeR[/eluser] Hi, i have a table with sellers and I need to create a row in another table containing the ID, Number of sales and Number of clients. So, the Controller gives me a $query with all the IDs and SELLERs, with this I need to select in the view the name of the "SELLER" (drop-down field) and also specify the "Number of sales" and the "Number of Clients" and finally send all this to the DB. It might be needed insert any number of SELLERS at once. please... help... ![]() I understand how to get the query from MySQL, but i don't know how to identify and work with multiple fields from the same type (many sellers). How to insert multiple rows from a single view. - El Forum - 08-06-2011 [eluser]pickupman[/eluser] Feel free to post some code of what you may have. Here is something you find useful. Code: //$sellers is query returned from DB How to insert multiple rows from a single view. - El Forum - 08-06-2011 [eluser]FlingeR[/eluser] Hi, thanks for the help. But I need to insert 20 or more sellers in one click, with that code i only can insert one at a time, and that's the matter. ![]() How to insert multiple rows from a single view. - El Forum - 08-07-2011 [eluser]bproctor[/eluser] I'm not sure I understand exactly, but it sounds like you have a form with multiple rows, and three columns, the seller, number of sales and number of clients and you want to fill all these out and click submit and have all those rows be inserted into the database... Code: <?php for ($i = 0; $i < 20; $i++) : ?> Then simply insert the entire post array into the database... Code: $this->db->insert_batch('my_table', $this->input->post()); Or if you need to have finer control over the data going into the database you could run it though a loop, something like this... Code: $post = $this->input->post(); How to insert multiple rows from a single view. - El Forum - 08-12-2011 [eluser]FlingeR[/eluser] Thanks to @bproctor and @pickupman for the help ! |