Reputation: 962
i am using cakephp. and want to display all data in database in dropdown list. but it returns only last item. there is some problem in loop. my code is below.
foreach ($origions as $or);
$id = $or["origions"]["id"];
$orgn = $or["origions"]["origion"];
$options = array($id=>$orgn);
echo $this->Form->select('origions.origion', $options);
this display only last record in dropdown list. please help what to do that all data in table display over here.
Upvotes: 1
Views: 1067
Reputation: 332
OTHER WAY (more optimized code)...
You can set Your data $this->set
from the controller.
From controller You can combine / extract / merge / sort / etc... multidimensional arrays like:
$result = Set::combine($origions, '{n}.origions.id', '{n}.origions.origion');
Read more about Cakephp SET::array functions http://book.cakephp.org/2.0/en/core-utility-libraries/set.html
Upvotes: 0
Reputation: 26431
Change it to,
$options = array();
foreach ($origions as $or){
$id = $or["origions"]["id"];
$orgn = $or["origions"]["origion"];
$options[$id] = $orgn;
}
echo $this->Form->select('origions.origion', $options);
For selected,
echo $this->Form->select('origions.origion', $options, array('value' => 'your_default_id'));
Upvotes: 2