Page 1 of 1

Setting initial option value of dropdown box

Posted: Tue Feb 15, 2011 5:08 pm
by cjkeane
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;
?>

Re: Setting initial option value of dropdown box

Posted: Tue Feb 15, 2011 6:36 pm
by social_experiment

Code: Select all

//
$dropdown = "<select name='CategoryTypes'>";
$dropdown .= "<option selected=\"selected\">Select from list</option>";
//
Hth