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.
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?
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.
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:
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: $rechnungs = $this->Setup_model->rechnungs(); //result should be an array of arrays foreach ($rechnungs as $rechnung) { $rechnung_new = $rechnung; unset($rechnung_new['id']); //remove the auto-increment ID from the record that is going to be inserted $id_old = $rechnung['id']; $this->db->insert('db_rechnung_new',$rechnung_new); $id_new = $this->db->insert_id(); $this->db->where('rechnung_id',$id_old); $this->db->set('rechnung_id',$id_new); $this->db->update('db_artikel'); //the old rechnung_id for the artikel is replaced by the new rechnung_id }