I apreciate if someone can help
I have a simple batch form [attachment=0]Captura.JPG[/attachment]
with simple code that changes format of some fields
after debugging, all records seem to be updated but although is a indexed list of records i can't save it into table 😲
[attachment=1]Captura1.JPG[/attachment]
I have a simple batch form [attachment=0]Captura.JPG[/attachment]
with simple code that changes format of some fields
<?php
$i=0;
foreach($form->data['paper'] as $var){
$form->data['paper'][$i]['id']=$var['id'];
$form->data['paper'][$i]['rates']=implode("/",explode(",",$var['rates']));
$form->data['paper'][$i]['rate1']=implode("/",explode(",",$var['rate1']));
$form->data['paper'][$i]['rate2']=implode("/",explode(",",$var['rate2']));
$form->data['paper'][$i]['rate3']=implode("/",explode(",",$var['rate3']));
$form->data['paper'][$i]['rate4']=implode("/",explode(",",$var['rate4']));
$i++;
}
?>
after debugging, all records seem to be updated but although is a indexed list of records i can't save it into table 😲
[attachment=1]Captura1.JPG[/attachment]
Hi teldrive,
What is the 'it' that you are trying to save??
You may need to escape values with / in them before saving.
Bob
What is the 'it' that you are trying to save??
You may need to escape values with / in them before saving.
Bob
Hi Bob thanks by reply, this fields rate1, rate 2 are varchar(255)
so by db-read and db-save are text fields, we just need change separators with php code "1,2,3,4,5" by "1/2/3/4/5", issue is that there are too many records to do it manually, so this is why we need this batch form
I saw in forums that is not supported to save more than one record with db-save, but some times dates of these answers are old, in CFv5(db-save action form) i see that if i have indexes lists i can save muliple records, my doubt is that I am assuming when i use db-read(multirecord) I obtain indexed list of record with same format that I need for db_save, i will apreciate if you can confirm me that.
so by db-read and db-save are text fields, we just need change separators with php code "1,2,3,4,5" by "1/2/3/4/5", issue is that there are too many records to do it manually, so this is why we need this batch form
I saw in forums that is not supported to save more than one record with db-save, but some times dates of these answers are old, in CFv5(db-save action form) i see that if i have indexes lists i can save muliple records, my doubt is that I am assuming when i use db-read(multirecord) I obtain indexed list of record with same format that I need for db_save, i will apreciate if you can confirm me that.
Hi Teldrive,
I'm not sure I understood your last post :-(
If you are just updating the database might it be easier to do this in PHPMyAdmin?
I still don't understand why you need to do that though.
Bob
I'm not sure I understood your last post :-(
If you are just updating the database might it be easier to do this in PHPMyAdmin?
UPDATE `some_table`
SET `rate1` = REPLACE(`rate1`, ',', '/');
I still don't understand why you need to do that though.
Bob
Hi Bob, I will try, but let me know anyway if i can do a multirecord db-load, change one field of each and after do a multirecord db-save,
Hi Teldrive,
There is no multi-record DB save action so you would have to hand-code this - it only needs a few lines of PHP in a Custom Code action. But the PHPMyAdmin route is going to be much quicker.
Bob
There is no multi-record DB save action so you would have to hand-code this - it only needs a few lines of PHP in a Custom Code action. But the PHPMyAdmin route is going to be much quicker.
Bob
Hi Bob , ok
this is what makes me confused[attachment=0]Captura.JPG[/attachment]
this is what makes me confused[attachment=0]Captura.JPG[/attachment]
Hi TelDrive,
Sorry, I'd forgotten this was CFv5 . . . I have no idea how that works, I'll go look at the code if I can find it.
Bob
Sorry, I'd forgotten this was CFv5 . . . I have no idea how that works, I'll go look at the code if I can find it.
Bob
Hi Teldrive,
Here's the function that does the multi-save
I think that requires that your data is supplied in an array that is numerically indexed starting with 0 - but that should be what your PHP returns.
Bob
Here's the function that does the multi-save
function saveAll($data = array()){
if(!empty($data) AND is_array($data) AND array_values($data) === $data){
//numerically indexed list of records
$this->ids = array();
foreach($data as $k => $record){
$this->save($record);
$this->ids[] = $this->id;
}
return true;
}
return false;
}
it looks straight-forward with the exception of the check array_values($data) === $data
I think that requires that your data is supplied in an array that is numerically indexed starting with 0 - but that should be what your PHP returns.
Bob
Hi Bob
let me know how can I match this->save with my table jos__XXXX, I am asuming with this function I don't need db-save action
let me know how can I match this->save with my table jos__XXXX, I am asuming with this function I don't need db-save action
Hi Teldrive,
According to your setup, the model name should be set to "paper" and the table should be selected with multi save enabled, then it should work!
Regards,
Max
According to your setup, the model name should be set to "paper" and the table should be selected with multi save enabled, then it should work!
Regards,
Max
Hi Max
I think so, it could be a bug, I made a simpler test, changing only one field of one record
debug shows all goes fine
[attachment=0]Captura1.JPG[/attachment]
but checking the field on table shows is not working
[attachment=1]Captura2.JPG[/attachment]
i think configuration on db-read is fine(I tested loading all fields too)
[attachment=2]Captura3.JPG[/attachment]
and in db-save also
[attachment=3]Captura4.JPG[/attachment]
I think so, it could be a bug, I made a simpler test, changing only one field of one record
<?php
$form->data['paper'][0]['rates']="testing";
?>
debug shows all goes fine
[attachment=0]Captura1.JPG[/attachment]
but checking the field on table shows is not working
[attachment=1]Captura2.JPG[/attachment]
i think configuration on db-read is fine(I tested loading all fields too)
[attachment=2]Captura3.JPG[/attachment]
and in db-save also
[attachment=3]Captura4.JPG[/attachment]
Hi Teldrive,
Please add a debugger action after the "db save" and post the debug data here.
Regards,
Max
Please add a debugger action after the "db save" and post the debug data here.
Regards,
Max
Hi Max, , hope it can help
[attachment=0]Captura.JPG[/attachment]
[attachment=0]Captura.JPG[/attachment]
Hi Teldrive,
I think that I found the bug, you can contact me using the "Contact us" page to get a fixed action file!
Regards,
Max
I think that I found the bug, you can contact me using the "Contact us" page to get a fixed action file!
Regards,
Max
Works perfect, thanks Max
This topic is locked and no more replies can be posted.