Brett, look:
BEGIN
  LOOP1 - $user_online = true;
  LOOP2 - $user_online = true;
  LOOP3 - $user_online = false;
END

SET VARIABLE TO VIEW
   $view->user_online = $user_online;

which value will be there in the view ?

  Now, the simplest way, is to use the user array itself:

foreach ($comments as $comment) {
  if (in_array($comment['Comment']['user_id'], $online_now))
  {
    $comment['Comment']['user_online'] = true;
  } else {
    $comment['Comment']['user_online'] = false;
  }
}

when looping the $comments variable in view, just use that
['Comment']['user_online'] array key.
and , pleeeease, don't use boolean variables as strings :)
"true" is not true

 Spark


On Feb 13, 2008 2:16 PM, butangphp <[EMAIL PROTECTED]> wrote:
>
> Hey all,
>
> I'm trying to create a condition in my controller within a foreach
> loop and then use this information in the view.
>
> A quick note, $comments is a proper array, as is $online_now, so it is
> not an array issue.  The question is where (or if) I can set the
> variable $user_online so that it it has a different value for each
> case ?  At the moment it is only returning the value of the last
> element in the array (so, if there are 15 elements and the 15th
> element is true, they are all true.  If the 15th element is false,
> they are all false.  )
>
> foreach ($comments as $comment) {
>
>         if (in_array($comment['Comment']['user_id'], $online_now))
>        {
>             $user_online = "true";
>        }
>         else
>         {
>             $user_online = "false";
>         }
> }
>
> $this->set('user_online', $user_online);
>
>
> Any help would be greatly appreciated!
> >
>



-- 
[livesets] http://djspark.com.br/
[web] http://sydi.net
[filmes] http://melhoresfilmes.com.br

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to