views:

21

answers:

1

I'm trying to get this loop to save a new record to the database in cakephp on each iteration but for some reason its only saving it on the last one (so in this case it saves a record called "test9" but no others.. this type of save has worked for me so far in cakephp and I am completely stumped by this, I would appreciate any advice

The debug output just gives this for each record (including the save that works), so I can't determine anything from it:

26 SELECT COUNT() AS count FROM proxylinks AS Proxylink WHERE Proxylink.id = 13 1 1 0 27 SELECT COUNT() AS count FROM proxylinks AS Proxylink WHERE Proxylink.id = 13 1 1 0 28 UPDATE proxylinks SET link = 'test9' WHERE proxylinks.id = 13 1 0

  $count = 10;
    $v = 1;
      do {

          ######### save link to database
          $this->Prox->Proxylink->set(array('link' => 'test' . $v));
          $this->Prox->Proxylink->save();

          $v++;
      } while ($v < $count);
+3  A: 

You have to call ->create(), otherwise it's updating the previously saved record.

Quoting the manual:

When calling save in a loop, don't forget to call create().

deceze
thanks.. yeah I just saw that actually, sorry for asking a dumb question :).. its just I could've sworn it worked fine before for me where it would create a new row without me calling this so I guess I never realized this was necessary
Rick