This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use the new forum.
Home » legacy support » symfony 1.2 » [SOLVED] One problem while performing inserts
[SOLVED] One problem while performing inserts [message #102596] Fri, 16 July 2010 14:39 Go to next message
xare  is currently offline xare
Messages: 14
Registered: June 2010
Junior Member
Hello

I am facing the following problem. I am trying to loop over an array of and make an insert on a table for every time we loop over the array but I find that only the last element gets looped

Here is the relevant piece of codeƑ

 $friends = $talent->getFriendshipsRelatedByTalentId();
        $fans  = $talent->getFanClubsRelatedByTalentId();


These are the 2 arrays that will be looped. And these are the two pieces of code that perform the loop and send to data to the database.

foreach ($friends as $friend) {
     $dups[] = $friend->getFriendId();
     $st->setRecipId($friend->getFriendId());
     $st->save();
}

 foreach ($fans as $fan) {
   if (false == in_array($fan->getTalentFan(), $dups)) {  //don't send it twice!
   $st->setRecipId($fan->getTalentFan());
   $st->save();
}
$con->commit();

}



The idea is to make a new row on a table for every loop. There are two loops but I found out that the problem is that only the last loop of both gets performed and the rest is not inserted.

Thanks for the help.

[Updated on: Mon, 19 July 2010 10:23]

Re: One problem while performing inserts [message #102682 is a reply to message #102596 ] Sun, 18 July 2010 01:31 Go to previous messageGo to next message
myuser  is currently offline myuser
Messages: 11
Registered: July 2010
Junior Member
It seems like you need to create a new object for each one you are trying to insert. Does that make sense? I'm still learning.


Symfony 1.4
Fedora release 11 (Leonidas)
(PostgreSQL) 8.3.11
PHP 5.2.13 (cli)
IP address: haha ummm maybe next time
Re: One problem while performing inserts [message #102720 is a reply to message #102682 ] Mon, 19 July 2010 10:22 Go to previous messageGo to next message
xare  is currently offline xare
Messages: 14
Registered: June 2010
Junior Member
Exactly that was the problem and you pointed at the solution.

thanks
Re: [SOLVED] One problem while performing inserts [message #103380 is a reply to message #102596 ] Sun, 01 August 2010 22:55 Go to previous message
myuser  is currently offline myuser
Messages: 11
Registered: July 2010
Junior Member
Great! Post up your new code if you could next time. I would love to see it.

Glad you solved it though. Thanks for the reply.


Symfony 1.4
Fedora release 11 (Leonidas)
(PostgreSQL) 8.3.11
PHP 5.2.13 (cli)
IP address: haha ummm maybe next time
Previous Topic:Update YML from php
Next Topic:I18N DOCTRINE BEHAVIOUR - HELP
Goto Forum:
  

powered by FUDforum - copyright ©2001-2004 FUD Forum Bulletin Board Software