Welcome Guest, Not a member yet? Register   Sign In
Foreach Insert Problem

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.

PHP Code:
= array("","Cardmarket","Ebay","ETCG");
echo validation_errors(); ?>
echo form_open('setup/insert_step026'); ?>
<button type="submit" class="btn btn-default" data-toggle="tooltip" data-placement="top" title="Senden"><span class="glyphicon glyphicon-floppy-saved" aria-hidden="true"></span> Speichern</button>
<?php foreach ($rechnungs as $rechnung): ?>
<input type="text" class="form-control" name="add_setup_000[<?php echo $rechnung['tb_rechnung_id']; ?>]" value="<?php echo $rechnung['tb_rechnung_id']; ?>">
<input type="hidden" class="form-control" name="add_setup_001[<?php echo $rechnung['tb_rechnung_id']; ?>]" value="<?php echo $rechnung['tb_rechnung_datum']; ?>">
<input type="hidden" class="form-control" name="add_setup_002[<?php echo $rechnung['tb_rechnung_id']; ?>]" value="<?php echo $rechnung['tb_kunde_vorname']; ?>">
<input type="hidden" class="form-control" name="add_setup_009[<?php echo $rechnung['tb_rechnung_id']; ?>]" value="<?php echo $rechnung['tb_kunde_nachname']; ?>">
<input type="hidden" class="form-control" name="add_setup_010[<?php echo $rechnung['tb_rechnung_id']; ?>]" value="<?php echo $rechnung['tp_land_name']; ?>">
<input type="hidden" class="form-control" name="add_setup_003[<?php echo $rechnung['tb_rechnung_id']; ?>]" value="<?php echo $rechnung['tb_rechnung_status']; ?>">
<input type="hidden" class="form-control" name="add_setup_004[<?php echo $rechnung['tb_rechnung_id']; ?>]" value="<?php echo $rechnung['tb_briefmarke_art']; ?>">
<input type="hidden" class="form-control" name="add_setup_008[<?php echo $rechnung['tb_rechnung_id']; ?>]" value="<?php echo $rechnung['tb_briefmarke_sum']; ?>">
<input type="hidden" class="form-control" name="add_setup_005[<?php echo $rechnung['tb_rechnung_id']; ?>]" value="<?php echo $rechnung['tb_rechnung_betrag']; ?>">
<input type="hidden" class="form-control" name="add_setup_006[<?php echo $rechnung['tb_rechnung_id']; ?>]" value="<?php echo $rechnung['tb_rechnung_menge']; ?>">
<input type="hidden" class="form-control" name="add_setup_007[<?php echo $rechnung['tb_rechnung_id']; ?>]" value="<?php echo $shopliste[$rechnung['tb_rechnung_wo']];?>">
foreach ($artikels as $artikel):
<input type="text" name="add_setup_A00[<?php echo $artikel['tb_artikel_id']; ?>]" value="<?php echo $artikel['tb_artikel_id']; ?>">
<input type="hidden" name="add_setup_A01[<?php echo $artikel['tb_artikel_id']; ?>]" value="<?php echo $artikel['tb_artikel_anzahl']; ?>">
<input type="hidden" name="add_setup_A02[<?php echo $artikel['tb_artikel_id']; ?>]" value="<?php echo $artikel['tb_artikel_status']; ?>">
<input type="hidden" name="add_setup_A03[<?php echo $artikel['tb_artikel_id']; ?>]" value="<?php echo $artikel['tb_artikel_preis']; ?>">
<input type="hidden" name="add_setup_A16[<?php echo $artikel['tb_artikel_id']; ?>]" value="<?php echo $artikel['tb_artikel_produckt']; ?>">
<input type="hidden" name="add_setup_A17[<?php echo $artikel['tb_artikel_id']; ?>]" value="<?php echo $artikel['tb_artikel_produckt_typ']; ?>">
<input type="hidden" name="add_setup_A18[<?php echo $artikel['tb_artikel_id']; ?>]" value="<?php echo $artikel['tb_artikel_karte']; ?>">
<input type="hidden" name="add_setup_A19[<?php echo $artikel['tb_artikel_id']; ?>]" value="<?php echo $artikel['tb_artikel_karten_stats']; ?>">
<input type="hidden" name="add_setup_A20[<?php echo $artikel['tb_artikel_id']; ?>]" value="<?php echo $artikel['tb_artikel_edition_stats']; ?>">
<input type="hidden" name="add_setup_A21[<?php echo $artikel['tb_artikel_id']; ?>]" value="<?php echo $artikel['tb_artikel_sprache']; ?>">
<input type="hidden" name="add_setup_A22[<?php echo $artikel['tb_artikel_id']; ?>]" value="<?php echo $artikel['tb_artikel_auflage']; ?>">
<input type="hidden" name="add_setup_A23[<?php echo $artikel['tb_artikel_id']; ?>]" value="<?php echo $artikel['tb_artikel_qualitat']; ?>">
<input type="hidden" name="add_setup_A24[<?php echo $artikel['tb_artikel_id']; ?>]" value="<?php echo $artikel['tb_artikel_time_add']; ?>">
<input type="hidden" name="add_setup_A25[<?php echo $artikel['tb_artikel_id']; ?>]" value="<?php echo $artikel['tb_artikel_time_rese']; ?>">
<input type="hidden" name="add_setup_A26[<?php echo $artikel['tb_artikel_id']; ?>]" value="<?php echo $artikel['tb_artikel_time_sell']; ?>">
<input type="hidden" name="add_setup_A27[<?php echo $artikel['tb_artikel_id']; ?>]" value="<?php echo $artikel['tb_artikel_time_sent']; ?>">
<input type="hidden" name="add_setup_A28[<?php echo $artikel['tb_artikel_id']; ?>]" value="<?php echo $artikel['tb_artikel_zustand']; ?>">
<input type="hidden" name="add_setup_A15[<?php echo $artikel['tb_artikel_id']; ?>]" value="<?php echo $artikel['tb_artikel_rechnung']; ?>">
endforeach; ?>
<?php endforeach; ?>
echo form_close(); ?>


PHP Code:
            public function insert_step026($setup_000 0)
                    foreach (
$this->input->post('add_setup_000') as $setup_000)
$data = array(    'tb_rechnung_datum' => $this->input->post('add_setup_001')[$setup_000],
'tb_rechnung_status' => $this->input->post('add_setup_003')[$setup_000],
'tb_rechnung_betrag' => $this->input->post('add_setup_005')[$setup_000],
'tb_rechnung_menge' => $this->input->post('add_setup_006')[$setup_000],
'tb_rechnung_positionen' => 0,
$rechnung_id $this->db->insert_id();
                            foreach (
$this->input->post('add_setup_A00') as $setup_A00)
$data = array(    'tb_artikel_anzahl' => $this->input->post('add_setup_A01')[$setup_A00],
'tb_artikel_status' => $this->input->post('add_setup_A02')[$setup_A00],
'tb_artikel_rechnung' => $rechnung_id,


PHP Code:
            public function step026()
$head['header_warenkorb_artikels'] = $this->Warenkorb_model->header_warenkorb_artikels();
$head['header_warenkorb_produckts'] = $this->Warenkorb_model->header_warenkorb_produckts();
$data['rechnungs'] = $this->Setup_model->rechnungs();
$data['artikels'] = $this->Setup_model->artikels();

            public function 
// redirect('setup/step000');

Attached Files Thumbnail(s)

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.

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

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 insert
The new ID from table db_rechnung should be entered in table db_artikel in column tb_artikel_rechnung.

Quote:Also share database structure

Attached Files Thumbnail(s)

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:
$rechnung_id $this->db->insert_id(); 

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'];
  $id_new $this->db->insert_id();
  $this->db->update('db_artikel');  //the old rechnung_id for the artikel is replaced by the new rechnung_id


Theme © iAndrew 2016 - Forum software by © MyBB