user4030491
user4030491

Reputation:

how to write select option in cake php and show the result in options

<select>
<?php $result=mysql_query('select id from contact');
while($row=$result){
$id = $row['id'];
?>
<option value='<?php echo $id; ?>'><?php echo $id; ?></option>
<?php } ?>
</select >

How to write this select box in cakephp ..

Upvotes: 0

Views: 506

Answers (1)

Skatch
Skatch

Reputation: 2272

Make a list query in your controller (http://book.cakephp.org/2.0/en/models/retrieving-your-data.html):

$results = $this->Model->find('list', $options);

and then add it to the form element in your view (http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html):

$this->Form->input('Model.field', array('options' => $results));

Upvotes: 2

Related Questions