Hi everyone.
I have a dropdown box retrieving information from a column in a table. I wish the initial value to be <select from list>. Can anyone suggest a way to do that? thx.
<?php
$query="select CategoryName from categorytypes";
$result = mysql_query($query) or die(mysql_error());
$dropdown = "<select name='CategoryTypes'>";
while($row = mysql_fetch_assoc($result)) {
$dropdown .= "\r\n<option value='{$row['CategoryName']}'>{$row['CategoryName']}</option>";
}
$dropdown .= "\r\n</select>";
echo $dropdown;
?>
Setting initial option value of dropdown box
Moderator: General Moderators
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Setting initial option value of dropdown box
Code: Select all
//
$dropdown = "<select name='CategoryTypes'>";
$dropdown .= "<option selected=\"selected\">Select from list</option>";
//
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering