Forums

Data in Table 2 are not updated

Fredolino 12 Feb, 2016
Hi,

if I want to change data in the second table, then it is stored in the table as a new Daternsatz in the database. Normally, the changed value will be saved.
What is the problem?

Thank you very much.
F.
Fredolino 12 Feb, 2016

Hi,

if I want to change data in the second table, then it is stored in the table as a new Daternsatz in the database. Normally, the changed value will be saved.
What is the problem?

Thank you very much.
F.

GreyHead 12 Feb, 2016
HI Fredolino,

For a record to be updated there has to be a primary key value - id_auftrag in this case - which matches the existing record.

Bob
Fredolino 12 Feb, 2016
Hi Bob,

thanx for the tipp.
I must have a Costum Code in Setup bevor DB Save-Aktion (for 2n Table)?

F.
GreyHead 13 Feb, 2016
Hi Fredolino,

You have to include the record id in the data - you haven't said how this form works so hard to say more.

Bob
Fredolino 13 Feb, 2016
Hello,
in DB Save Action for the 2nd table I have this updated code:
<?php
return array('Firma_1.id_firma' => $form->data['Firma.id']);
?> 

In the DebugInfo the changed value is included. But if I see in the database, then the value is not stored but.
Where now is still the problem?

F.
Fredolino 14 Feb, 2016
Hi,
i have now in the DB Save Action this code:
<?php
return array('Firma_1.id_firma' => $form->data['Firma']['id']);
?> 


it seems to me all right in Debug Info (Screen), but the changed data is not saved. What is now the problem?

F.
GreyHead 14 Feb, 2016
Hi Fredolino,

Both queries are updating the record with the ID 423. Is that what you intend?

Bob
Fredolino 14 Feb, 2016
Hi Bob,

you're right, the Statement for the 2nd table (Model Firma_1) is incorrect.
Now there are 2 updates. However, it is only correct if only the record is updated, which is to save on the form the modified value in the database.

F.
GreyHead 14 Feb, 2016
Hi Fredolino,

You have to make sure that the ID matches the record that you want to update.

Bob
Fredolino 14 Feb, 2016
OK,
I give now only for the container with the change data a hidden field with the ID:
Firma_1[__N__][id_auftrag]
In Setup then then for the 2nd table in DB save:
<?php
return array('Firma_1.id_auftrag' => $form->data['Firma']['id']);
?>

But that does not work because I have to have the index of the array:
[0] or [1]
How do I get it?
GreyHead 15 Feb, 2016
Hi Fredolino,

Presumably the first one will be $form->data['Firma'][0]['id'] and the second one $form->data['Firma'][1]['id']

You could also use the Multi Save option in a single DB Save action.

Bob
Fredolino 15 Feb, 2016
Hi Bob,

following custome code before storing the second table in the setup seems to work:

<?php
	if (is_array($form->data['Firma_1']) && 
		is_array($form->data['Firma']) &&
		$form->data['Firma']['id'] <> 0)
	{
		foreach($form->data['Firma_1'] as $k => $v)
		{
		  $v['id_firma'] = $form->data['Firma']['id'];
		  $form->data['Firma_1'][$k] = $v;
		}
	}
?>


:-)

Thanks a lot!
F.
This topic is locked and no more replies can be posted.