Hello!
I'm trying to load different fields using DB read and, then, save all them (updating).
>> My table:
[attachment=84078_20170226131053_captura-jpg.jpg][/attachment]
I want to load the values from column "value" into two different fields.
So, using DB read I can put this in one DB READ action for the first value (field_id=2)
And another DB READ action fo the second value (when field_id=3)
But, I cannot have 2 fields in my form with the id "DATA[value]".
>> How can I do that??
Once loadad, I'll need also to save both updating existing fields (not creating new ones)
I'm trying to load different fields using DB read and, then, save all them (updating).
>> My table:
[attachment=84078_20170226131053_captura-jpg.jpg][/attachment]
I want to load the values from column "value" into two different fields.
So, using DB read I can put this in one DB READ action for the first value (field_id=2)
<?php
$user =& JFactory::getUser();
return array('user_id' =>$user->id, 'field_id' => 2);
?>
And another DB READ action fo the second value (when field_id=3)
<?php
$user =& JFactory::getUser();
return array('user_id' =>$user->id, 'field_id' => 3);
?>
But, I cannot have 2 fields in my form with the id "DATA[value]".
>> How can I do that??
Once loadad, I'll need also to save both updating existing fields (not creating new ones)
Hi Kronosites ,
You could load the data from a Custom Code action getting both values at the same time and then rename the loaded values.
Bob
You could load the data from a Custom Code action getting both values at the same time and then rename the loaded values.
Bob
Hello again!
I've solved the problem on loading lot of fields.
Now I want to save all of them updating existing values. How can I do that?
For example, according to the image posted on my first message, I've load the 2 fields from the column "value" into 2 different fields (I have used 2 DB read actions):
"value" = Hombre has loaded into my form, field id = K2[value]
"value" = 1987-2-20 has loaded into my form, field id = K3[value]
Now, I want to save this data updating existing one using "db save" actions.
How can I do it??
Thanks!!
I've solved the problem on loading lot of fields.
Now I want to save all of them updating existing values. How can I do that?
For example, according to the image posted on my first message, I've load the 2 fields from the column "value" into 2 different fields (I have used 2 DB read actions):
"value" = Hombre has loaded into my form, field id = K2[value]
"value" = 1987-2-20 has loaded into my form, field id = K3[value]
Now, I want to save this data updating existing one using "db save" actions.
How can I do it??
Thanks!!
Hi Kronosites,
A bit short of information here to know the best way to do this. One way would be a Custom Code action with code like this
Bob
A bit short of information here to know the best way to do this. One way would be a Custom Code action with code like this
$db = \JFactory::getDBO();
$query = "
UPDATE `#__table_name`
SET `value` = '{$form->data['K2']}'
WHERE `user_id` = '{$form->data['user_id']}' AND `field_id` = 2;
";
$db->setQuery($query);
$db-execute();
$query = "
UPDATE `#__table_name`
SET `value` = '{$form->data['K3']}'
WHERE `user_id` = '{$form->data['user_id']}' AND `field_id` = 3;
";
$db->setQuery($query);
$db-execute();
?>
Bob
Hi again,
Something is failing (when I click on submit button a blank page appears, without information).
>> Debugger when onload:
So, I want to save the data of K2[value] and K3[value]
>> Custom code in "submit" event:
Something is failing (when I click on submit button a blank page appears, without information).
>> Debugger when onload:
Array
(
[K2] => Array
(
[id] => 3
[user_id] => 955
[field_id] => 4
[value] => TEXT1TOSAV
)
[K3] => Array
(
[id] => 10
[user_id] => 955
[field_id] => 12
[value] => TEXT2TOSAVE
)
)
So, I want to save the data of K2[value] and K3[value]
>> Custom code in "submit" event:
<?php
$db = \JFactory::getDBO();
$query = "
UPDATE `xxx_xxx_xxx`
SET `value` = '{$form->data['K2']}'
WHERE `user_id` = '{$form->data['user_id']}' AND `field_id` = 2;
";
$db->setQuery($query);
$db-execute();
$query = "
UPDATE `xxx_xxx_xxx`
SET `value` = '{$form->data['K3']}'
WHERE `user_id` = '{$form->data['user_id']}' AND `field_id` = 3;
";
$db->setQuery($query);
$db-execute();
?>
Hi Kronosites ,
You need to debug the code to work with the real data you have - from the Debugger you can see that $form->data['K2'] is an array of values not a single value.
Bob
You need to debug the code to work with the real data you have - from the Debugger you can see that $form->data['K2'] is an array of values not a single value.
Bob
Yes, your right,
But I'm trying to use this array correctly but I can't, blank page appears when click on submit button:
But I'm trying to use this array correctly but I can't, blank page appears when click on submit button:
<?php
$db = \JFactory::getDBO();
$query = "
UPDATE `xxxx_xxxx_xxxx`
SET `value` = '{form->data['K2']['value']}'
WHERE `user_id` = '{$form->data['K2']['user_id']}' AND `field_id` = 2;
";
$db->setQuery($query);
$db-execute();
?>
Hi Kronosites ,
If you set the Site Error Reporting to Maximum temporarily then you should see a PHP Error message that will help you debug your custom code.
Bob
If you set the Site Error Reporting to Maximum temporarily then you should see a PHP Error message that will help you debug your custom code.
Bob
Thanks GreyHead,
I have problems with the error reporting but I found the issue.
I let the full code corrected, it's working PERFETLY (we love chronoforms!):
Thanks!
I have problems with the error reporting but I found the issue.
I let the full code corrected, it's working PERFETLY (we love chronoforms!):
<?php
$db = \JFactory::getDBO();
$query = "
UPDATE `PUT_HERE_THE_NAME_OF_THE_TABLE`
SET `value` = '{$form->data['K2']['value']}'
WHERE `user_id` = '{$form->data['K2']['user_id']}' AND `field_id` = 4;
";
$db->setQuery($query);
$db->execute();
?>
Thanks!
This topic is locked and no more replies can be posted.