Re: Saving in a loop

2007-04-03 Thread BlenderStyle

After looking at the link Dr. Tarique Sani posted, try this:

for ( $counter = 0; $counter = 4; $counter += 1) {
 $this-data['Person']['first_name'] = 'First Name ' .
$counter;
 $this-data['Person']['last_name'] = 'Last Name ' . $counter;
 $this-data['Person']['age'] = 50 + $counter;
 $this-Person-create();
 $this-Person-save($this-data);
  }

On Apr 2, 9:59 pm, behrangsa [EMAIL PROTECTED] wrote:
 Hi,

 When I execute the following code, only one item gets inserted into the
 people table:

 for ( $counter = 0; $counter = 4; $counter += 1) {
  $this-data['Person']['first_name'] = 'First Name ' . $counter;
  $this-data['Person']['last_name'] = 'Last Name ' . $counter;
  $this-data['Person']['age'] = 50 + $counter;
  $this-Person-save($this-data);
   }

 Any ideas why? How can I insert 5 items in a loop like above to the
 database?

 Regards,
 Behi
 --
 View this message in 
 context:http://www.nabble.com/Saving-in-a-loop-tf3509818.html#a9803735
 Sent from the CakePHP mailing list archive at Nabble.com.


--~--~-~--~~~---~--~~
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 in a loop

2007-04-03 Thread behrangsa


Thanks,

I solved the problem by nullifying the id in the loop :-)

Looks like the correct way of handling is to call the Create function.

Regards,
Behi


Dr. Tarique Sani wrote:
 
 
 On 4/3/07, behrangsa [EMAIL PROTECTED] wrote:
 When I execute the following code, only one item gets inserted into the
 people table:

 for ( $counter = 0; $counter = 4; $counter += 1) {
  $this-data['Person']['first_name'] = 'First Name ' . $counter;
  $this-data['Person']['last_name'] = 'Last Name ' . $counter;
  $this-data['Person']['age'] = 50 + $counter;
  $this-Person-save($this-data);
   }
 
 http://groups.google.com/group/cake-php/search?hl=engroup=cake-phpq=saving+in+loopqt_g=Search+this+group
 
 Do your homework if you don't want your head to be bitten off ;)
 
 Tarique
 -- 
 =
 PHP for E-Biz: http://sanisoft.com
 Cheesecake-Photoblog needs you!: http://cheesecake-photoblog.org
 =
 
  
 
 

-- 
View this message in context: 
http://www.nabble.com/Saving-in-a-loop-tf3509818.html#a9813961
Sent from the CakePHP mailing list archive at Nabble.com.


--~--~-~--~~~---~--~~
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 in a loop

2007-04-03 Thread BlenderStyle

I guess that would have worked too. ($this-Person-id = null;). I
took me awhile to realize that $this-ModelName-id is generated
automatically at times. I still don't understand how it works
completely. I've had edit methods that work even though I didn't
really deal with the id like I thought I should.

On Apr 3, 7:54 am, behrangsa [EMAIL PROTECTED] wrote:
 Thanks,

 I solved the problem by nullifying the id in the loop :-)

 Looks like the correct way of handling is to call the Create function.

 Regards,
 Behi



 Dr. Tarique Sani wrote:

  On 4/3/07, behrangsa [EMAIL PROTECTED] wrote:
  When I execute the following code, only one item gets inserted into the
  people table:

  for ( $counter = 0; $counter = 4; $counter += 1) {
   $this-data['Person']['first_name'] = 'First Name ' . $counter;
   $this-data['Person']['last_name'] = 'Last Name ' . $counter;
   $this-data['Person']['age'] = 50 + $counter;
   $this-Person-save($this-data);
}

 http://groups.google.com/group/cake-php/search?hl=engroup=cake-phpq...

  Do your homework if you don't want your head to be bitten off ;)

  Tarique
  --
  =
  PHP for E-Biz:http://sanisoft.com
  Cheesecake-Photoblog needs you!:http://cheesecake-photoblog.org
  =

 --
 View this message in 
 context:http://www.nabble.com/Saving-in-a-loop-tf3509818.html#a9813961
 Sent from the CakePHP mailing list archive at Nabble.com.


--~--~-~--~~~---~--~~
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 in a loop

2007-04-03 Thread Chris Lamb
BlenderStyle [EMAIL PROTECTED] wrote:

 I still don't understand how it works completely.

Take a look at the Cake source - it's not that scary, and will improve
your understanding far greater than anything written in English.

Regarding the create function, I would suggest using create() over
setting id to null as it follows the same verb used when discussing the
active record pattern elsewhere: having a consistent lexicon is one of
the key points of Design Patterns. In addition, calling the create()
allows one to override the functionality in your model in the future, if
you need to.

-- 
 Chris Lamb, Cambridgeshire, UK  GPG: 0x634F9A20


signature.asc
Description: PGP signature


Re: Saving in a loop

2007-04-02 Thread Dr. Tarique Sani

On 4/3/07, behrangsa [EMAIL PROTECTED] wrote:
 When I execute the following code, only one item gets inserted into the
 people table:

 for ( $counter = 0; $counter = 4; $counter += 1) {
  $this-data['Person']['first_name'] = 'First Name ' . $counter;
  $this-data['Person']['last_name'] = 'Last Name ' . $counter;
  $this-data['Person']['age'] = 50 + $counter;
  $this-Person-save($this-data);
   }

http://groups.google.com/group/cake-php/search?hl=engroup=cake-phpq=saving+in+loopqt_g=Search+this+group

Do your homework if you don't want your head to be bitten off ;)

Tarique
-- 
=
PHP for E-Biz: http://sanisoft.com
Cheesecake-Photoblog needs you!: http://cheesecake-photoblog.org
=

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---