Monday, January 21, 2013

Re: foreach loop in select option

On Mon, Jan 21, 2013 at 1:48 PM, PlanoCoder <lance@lancebarron.com> wrote:
> So i need to turn the foreach look into an array. then pass the array to the
>
> $this->Form->select('player', $options); where $options is the array from
> the foreach loop.
>
> My question is, how do i turn the data from the foreach loop into an array?

You could do it with a loop or make use of the Set or Hash classes.
In your controller, after you find your data:

$options = array();

foreach($data as $d)
{
$options[$d['Player']['id']] = 'Team: '. $d['Player']['team'] . '
Number: ' . $d['Player']['number'];
}

$this->set(compact('options'));

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate