Hi,
I have one model that contains array of values. I need to save this model several times - every record differs only by the value of array. For example array contains {17, 3, 9} so I want to have 3 record in my DB. How can I do this?
Hi,
I have one model that contains array of values. I need to save this model several times - every record differs only by the value of array. For example array contains {17, 3, 9} so I want to have 3 record in my DB. How can I do this?
count the array
then use the for loop or while or foreach
and save the record as
model->save()
Thaks for reply, I did it this way, but there where problem. Its solved now
how do you solve you problem . its my problem now …
here is my code
if(isset($_POST['komponent'])){
// return;
//print_r($_POST['komponent']); // [0] => a [1] => b
foreach ($_POST['komponent'] as $kompon):
$mod = array("komponent" => $kompon);
//ECHO $kompon."</br>";
print_r($mod); //Array ( [komponent] => Array ( [0] => a [1] => b ) )
$modelb->attributes= $mod;
$modelb->save();
endforeach;
}
when i look the array output look like this .
Array ( [komponent] => aaaa ) Array ( [komponent] => bbb ) Array ( [komponent] => vvvv )
but when i see the stored database just the last recored stored
need your help
If you call CActiveRecord.save() the first time, CActiveRecord.isNewRecord will be set to false. All following calls will then update the inserted record instead of creating a new one. A quick-‘n’-dirty hack would be to set isNewRecord to true within your loop. But really, it were much better to just create a new model and save that
yeah … now i know what i miss …
so i will try with for loop
thanks you