| Author |
Message |
Desbrina Jadeite

Joined: 11 Jun 2005 Posts: 2963 Location: Earth
|
Posted: Fri Nov 09, 2007 8:33 am Post subject: php mysql option box question |
|
|
I have an option box that i have several options in. What i want to do is be able to have it select the one that is in the database.
So the options are
Now, Later, Before
and in the database the field is called time
I want it to be automatically selecting the correct one, how do i go about this? _________________ Midnight Tempest - A Sailor Moon TCG
Balanced Force - A Star Wars TCG |
|
| Back to top |
|
| |
krt ...

Joined: 11 Jan 2005 Posts: 4619 Location: Down Under
|
Posted: Fri Nov 09, 2007 5:18 pm Post subject: |
|
|
Loop over the options and add selected attribute to the appropriate one. Assuming interspersed HTML:
| Code: | $options = array('Now', 'Later', 'Before');
$current = 'Now';
echo '<select>';
foreach ($options as $k=>$v)
echo '<option value="'.$v.'"'.($v==$current ? 'selected="selected"' : '').'>'.$v.'</option>';
echo '<select>'; |
|
|
| Back to top |
|
| |
Desbrina Jadeite

Joined: 11 Jun 2005 Posts: 2963 Location: Earth
|
|
| Back to top |
|
| |
|
|
|