开发者

Cakephp looping through database saves, for some reason it only saves on the last instance of loop?

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);


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().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜