Re: Saving to database

2007-07-25 Thread Pablo Viojo
Better use this->Box->create() before saving to create a new Model object


-- 
Pablo Viojo
[EMAIL PROTECTED]
http://pviojo.net


On 7/25/07, Unite <[EMAIL PROTECTED]> wrote:
>
>
> Fixed it. Needed a $this->Box->id= null; in
> if(!empty($temp)) { //incase user skipped that box
> $this->Box->save($temp); //Writes over old data and
> pointer doesnt
> move
> }
>
> On Jul 25, 12:43 pm, Unite <[EMAIL PROTECTED]> wrote:
> > Heres the problem. I am filling in forms and saving them to a session.
> > These forms are repeats of themselves so basically in the session a
> > array of how ever many forms the user made is saved to the session.
> > Simple terms a session gets saved as a array of a forms data eg:
> > array(box1,box2,box3.). Now the problem I am having is that if I
> > try save these forms to a table (exact fields) using a foreach loop
> > only the last "box" is recorded. It seems to me that the
> $this->Table->save() method is just replacing the old data with the new data
> >
> > instead of incrementing the id (primary key) so the pointer isnt
> > moving onto the next record. Is there a way to force this behaviour?
> >
> > $templatedata = $this->Session->read('templatedata'); //This is the
> > array of box's
> > foreach($templatedata as $temp) {
> > if(!empty($temp)) { //incase user skipped that box
> > $this->Box->save($temp); //Writes over old data and
> pointer doesnt
> > move
> > }
> >
> > }
> >
> >
> **
> > example of output
> >
> **
> > Array //if a pr($temp) was in the if statement
> > (
> > [sender_id] => 8
> > [index_id] => 2
> > [amt_fields] => 2
> > [box_name] => j
> > [bg_colour] => j
> > [hasborder] => No
> > [border_colour] => j
> > [font_colour] => j
> > [font_style] => j
> > [field0] => j
> > [field1] => j
> > )
> >
> > Array //if a pr($temp) was in the if statement
> > (
> > [sender_id] => 8
> > [index_id] => 4
> > [amt_fields] => 1
> > [box_name] => 5
> > [bg_colour] => 5
> > [hasborder] => Yes
> > [border_colour] => 5
> > [font_colour] => 5
> > [font_style] => 5
> > [field0] => 5
> > )
> >
> > Array //if a pr($this->Box->findAll()); was at end of function
> > (
> > [0] => Array
> > (
> > [box] => Array
> > (
> > [id] => 1
> > [sender_id] => 8
> > [index_id] => 4
> > [amt_fields] => 1
> > [box_name] => 5
> > [logo] =>
> > [field0] => 5
> > [field1] => j //not ment to be here left over from
> > first record
> > [field2] =>
> > [field3] =>
> > [field4] =>
> > [field5] =>
> > [field6] =>
> > [field7] =>
> > [field8] =>
> > [field9] =>
> > [bg_colour] => 5
> > [font_colour] => 5
> > [font_style] => 5
> > [hasborder] => Yes
> > [border_colour] => 5
> > )
> >
> > )
> >
> > }
>
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: Saving to database

2007-07-25 Thread Unite

Fixed it. Needed a $this->Box->id= null; in
if(!empty($temp)) { //incase user skipped that box
$this->Box->save($temp); //Writes over old data and
pointer doesnt
move
}

On Jul 25, 12:43 pm, Unite <[EMAIL PROTECTED]> wrote:
> Heres the problem. I am filling in forms and saving them to a session.
> These forms are repeats of themselves so basically in the session a
> array of how ever many forms the user made is saved to the session.
> Simple terms a session gets saved as a array of a forms data eg:
> array(box1,box2,box3.). Now the problem I am having is that if I
> try save these forms to a table (exact fields) using a foreach loop
> only the last "box" is recorded. It seems to me that the $this->Table->save() 
> method is just replacing the old data with the new data
>
> instead of incrementing the id (primary key) so the pointer isnt
> moving onto the next record. Is there a way to force this behaviour?
>
> $templatedata = $this->Session->read('templatedata'); //This is the
> array of box's
> foreach($templatedata as $temp) {
> if(!empty($temp)) { //incase user skipped that box
> $this->Box->save($temp); //Writes over old data and pointer 
> doesnt
> move
> }
>
> }
>
> **
> example of output
> **
> Array //if a pr($temp) was in the if statement
> (
> [sender_id] => 8
> [index_id] => 2
> [amt_fields] => 2
> [box_name] => j
> [bg_colour] => j
> [hasborder] => No
> [border_colour] => j
> [font_colour] => j
> [font_style] => j
> [field0] => j
> [field1] => j
> )
>
> Array //if a pr($temp) was in the if statement
> (
> [sender_id] => 8
> [index_id] => 4
> [amt_fields] => 1
> [box_name] => 5
> [bg_colour] => 5
> [hasborder] => Yes
> [border_colour] => 5
> [font_colour] => 5
> [font_style] => 5
> [field0] => 5
> )
>
> Array //if a pr($this->Box->findAll()); was at end of function
> (
> [0] => Array
> (
> [box] => Array
> (
> [id] => 1
> [sender_id] => 8
> [index_id] => 4
> [amt_fields] => 1
> [box_name] => 5
> [logo] =>
> [field0] => 5
> [field1] => j //not ment to be here left over from
> first record
> [field2] =>
> [field3] =>
> [field4] =>
> [field5] =>
> [field6] =>
> [field7] =>
> [field8] =>
> [field9] =>
> [bg_colour] => 5
> [font_colour] => 5
> [font_style] => 5
> [hasborder] => Yes
> [border_colour] => 5
> )
>
> )
>
> }


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Saving to database

2007-07-25 Thread Unite

Heres the problem. I am filling in forms and saving them to a session.
These forms are repeats of themselves so basically in the session a
array of how ever many forms the user made is saved to the session.
Simple terms a session gets saved as a array of a forms data eg:
array(box1,box2,box3.). Now the problem I am having is that if I
try save these forms to a table (exact fields) using a foreach loop
only the last "box" is recorded. It seems to me that the $this->Table-
>save() method is just replacing the old data with the new data
instead of incrementing the id (primary key) so the pointer isnt
moving onto the next record. Is there a way to force this behaviour?

$templatedata = $this->Session->read('templatedata'); //This is the
array of box's
foreach($templatedata as $temp) {
if(!empty($temp)) { //incase user skipped that box
$this->Box->save($temp); //Writes over old data and pointer 
doesnt
move
}
}

**
example of output
**
Array //if a pr($temp) was in the if statement
(
[sender_id] => 8
[index_id] => 2
[amt_fields] => 2
[box_name] => j
[bg_colour] => j
[hasborder] => No
[border_colour] => j
[font_colour] => j
[font_style] => j
[field0] => j
[field1] => j
)

Array //if a pr($temp) was in the if statement
(
[sender_id] => 8
[index_id] => 4
[amt_fields] => 1
[box_name] => 5
[bg_colour] => 5
[hasborder] => Yes
[border_colour] => 5
[font_colour] => 5
[font_style] => 5
[field0] => 5
)

Array //if a pr($this->Box->findAll()); was at end of function
(
[0] => Array
(
[box] => Array
(
[id] => 1
[sender_id] => 8
[index_id] => 4
[amt_fields] => 1
[box_name] => 5
[logo] =>
[field0] => 5
[field1] => j //not ment to be here left over from
first record
[field2] =>
[field3] =>
[field4] =>
[field5] =>
[field6] =>
[field7] =>
[field8] =>
[field9] =>
[bg_colour] => 5
[font_colour] => 5
[font_style] => 5
[hasborder] => Yes
[border_colour] => 5
)

)
}


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---