Forums

Multisave indexed list of records

teldrive 31 May, 2014
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
<?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]
GreyHead 02 Jun, 2014
Hi teldrive,

What is the 'it' that you are trying to save??

You may need to escape values with / in them before saving.

Bob
teldrive 02 Jun, 2014
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.
GreyHead 02 Jun, 2014
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?
UPDATE `some_table`
SET `rate1` = REPLACE(`rate1`, ',', '/');


I still don't understand why you need to do that though.

Bob
teldrive 02 Jun, 2014
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,
GreyHead 02 Jun, 2014
Answer
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
teldrive 02 Jun, 2014
Hi Bob , ok
this is what makes me confused[attachment=0]Captura.JPG[/attachment]
GreyHead 02 Jun, 2014
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
GreyHead 02 Jun, 2014
Hi Teldrive,

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
teldrive 02 Jun, 2014
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
Max_admin 03 Jun, 2014
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
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
teldrive 03 Jun, 2014
Hi Max
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]
Max_admin 03 Jun, 2014
Hi Teldrive,

Please add a debugger action after the "db save" and post the debug data here.

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
teldrive 03 Jun, 2014
Hi Max, , hope it can help
[attachment=0]Captura.JPG[/attachment]
Max_admin 04 Jun, 2014
1 Likes
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
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
teldrive 04 Jun, 2014
Works perfect, thanks Max
This topic is locked and no more replies can be posted.