CakePHP retrieve loop data in the select array -
now got table contact. contact have 2 row id , name. got 3 user in contact,
1
2 b
3 c
question.
how make select input code of below ( in cakephp ):
<select name="contact" id="userfield">
<?php for($i=1;$i<=3; $i++) ?>
<option value="1"><?php echo $contact['contact']['name']; ?></option>
</select>
in controllers action can set list of names
$names = $this->contact->find('list', array( 'contain' => array(), 'fields' => array( 'contact.id', 'contact.name' ), 'order' => array( 'contact.name' => 'asc' ) )); $this->set(compact('names'));
and in view
echo $this->form->input('contact', array( 'label' => 'contact', 'options' => $names ));
Comments
Post a Comment