Hi!
First of all, check out if duplicating this data (twice the same
values in 2 tables) really makes sense,
or if you can figure out another logic. ;-)
Ok, this one way i solved it. Using another table means for me, using
another model. Create
the second model for the second table. Use the foreign model and save
it. This example is
from my finca renting site. Requests and Collections (Fincas on a
notepad) are the two models.
In this case i just copy each array part and submit several requests
with a collection.
Also i add some needed fields from the model Request. Hope this helps
you ;)
class CollectionsController extends AppController {
var $name = 'Collection';
var $uses = array('Request');
var $helpers = array('Lightbox', 'Javascript');
function add() {
$this->layout = "domizile";
if(isset($this->data)) {
$notepads =
array_unique($this->Session->read('notepad'));
$c=-1;
foreach ($notepads AS $marked) {
$c++;
$this->data['Request'][$c] =
$this->data['Collection'];
$this->data['Request'][$c]['finca_id'] =
$marked;
$this->data['Request'][$c]['booked'] = false;
}
if ($this->Request->saveAll($this->data['Request'])) {
$this->Session->setFlash(sprintf(__('Thanks for
your request',
true)));
} else {
$this->Session->setFlash(sprintf(__('Error on
request', true)));
}
}
}
}
?>
On 2 Sep., 05:31, Cruisine <[email protected]> wrote:
> hi guys, i 've just met a terrible problem when i would like to copy
> multiple data from one table and add those datas (which is have the
> same foreign key) into another table in one time..
> for example, firstly i want to copy the following data from table
> 'eating' :
>
> array (
> [Eating]=array
> (
> [0]=array
> (
> [people_id]=1
> [food]=spagheti
> )
> [1]=array
> (
> [people_id]=1
> [food]=burger
> )
> [2]=array
> (
> [people_id]=1
> [food]=rice
> )
> )
> )
>
> from the copied data that shown above they are have the same
> people_id..it means one person can eat some food..
>
> after i copied those datas..i want to add them into another table
> which have the same table structure...
> i've tried to use 'for' looping to handle this problem..but seems it
> didn't works..it saved just one row from the existing data..
>
> are u guys know how to handle this problem?
> need ur help soon
> tq.
Check out the new CakePHP Questions site http://cakeqs.org and help others with
their CakePHP related questions.
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en