[eluser]roy3600[/eluser]
Hey guys,
Trying to create a simple drop down menu that populates via a table from my database. A simple "States" dropdown.
I have no problem doing this in normal PHP, here is my code:
Code:
<label for="state">State:</label>
<select name="state" id="state">
<?php
$state=mysql_query("SELECT * FROM states");
while($rows=mysql_fetch_assoc($state)){
?>
<option value="<?php echo $rows['state']; ?>"><?php echo $rows['state']; ?></option>
<?php }?>
</select>
However, I really want to learn Code Igniter and do this the correct way. I found on the User Guide this syntax for a dropdown:
$options = array(
'small' => 'Small Shirt',
'med' => 'Medium Shirt',
'large' => 'Large Shirt',
'xlarge' => 'Extra Large Shirt',
);
$shirts_on_sale = array('small', 'large');
echo form_dropdown('shirts', $options, 'large');
However, this does not show how to populate via a table, and I'm not to great at arrays and working with PHP While Loops inside of them.
Any help is appreciated, thanks!