![]() |
Foreach Insert Problem - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: General (https://forum.codeigniter.com/forumdisplay.php?fid=1) +--- Forum: Regional User Groups (https://forum.codeigniter.com/forumdisplay.php?fid=25) +--- Thread: Foreach Insert Problem (/showthread.php?tid=69623) |
Foreach Insert Problem - Germanikus - 12-26-2017 Hello together and a merry christmas afterwards, I have two loops in a view and a form_open. in the red loop, the bills are displayed and in the second, green marked the other loop is displayed. Now I want to enter the value of the red in the green (ie the ID). I have already tried everything for me questionable. I hope you can continue helping me there. view: PHP Code: <?php Model: PHP Code: public function insert_step026($setup_000 = 0) Controller: PHP Code: public function step026() RE: Foreach Insert Problem - Wouter60 - 12-26-2017 Let me get this straight. Your form displays existing bills, and for each bill the existing products that are linked to it, right? What's the point in letting the user change the bill id, and then insert the records into the database again, in stead of updating the existing data? You could help us if you write down the proces first: what do you want to achieve (and why)? Which data do you have, and what do you want it to look like after the user submits the form? RE: Foreach Insert Problem - Germanikus - 12-26-2017 You understood that correctly. As this website is only for me and nobody else has access, the ID of the bill can change. Also, I would need this method also somewhere else and could help me well. The procedure should be saved with the sending of the button all displayed invoices in the new database. RE: Foreach Insert Problem - XtreemDeveloper - 12-26-2017 what exactly functionality do you want in that. Write down proces: What do you want achieve. What content do you want insert Also share database structure RE: Foreach Insert Problem - Germanikus - 12-26-2017 Quote: What do you want achieve.I would like to have the IDs of the invoice filled anew and the new ID should be entered in the new occupation of the articles. Quote:What content do you want insertThe new ID from table db_rechnung should be entered in table db_artikel in column tb_artikel_rechnung. Quote:Also share database structureDown RE: Foreach Insert Problem - Wouter60 - 12-26-2017 You say you want to enter a new ID for each invoice (Rechnung) in the form. But in your model, you let the database determine the new ID for the invoice: PHP Code: $this->db->insert('db_rechnung', $data); If the ID-field is an auto-increment field, you can't use a POST value from a form to store it's value. So there is no need to ask for in the form. I wonder whether you need a form in the first place. Why don't you simply read all invoices one by one (in a foreach loop), remember the current ID (in an variable); then save the record into the other table you have, and then do update in the db_artikel table: PHP Code: //This code goes in your controller: |