View Full Version : Selecting Initial Value on a dynamic dropdown box

06-29-2007, 03:40 PM
I have a drop down box and am trying to figure out how to select the initial value from the results of a query on my page. Any help would be greatly appreciated.

Here is my dropdown:

<select name="dcstatus" id="dcstatus">
<option value="">Please Choose One</option>
<?php do { ?><option value="<?php echo $row_folder_status['dcstatusid']; ?>"><?php echo $row_folder_status['dcstatusname']; ?></option><?php } while ($row_folder_status = mysql_fetch_array($folder_status)); ?>

Here is my query:

$folder = mysql_query("SELECT dcname, dcdescription, dcparent, dccreator, dcstatus FROM dcmain WHERE dcid = '$dcid'") or die(mysql_error());
$row_folder = mysql_fetch_array($folder);
$row_folder_total = mysql_num_rows($folder);

06-29-2007, 03:46 PM
use a counter, and if the counter is equal to 1, then print selected="selected"

else do nothing


06-29-2007, 05:48 PM
Which option did you want to set to be selected? If it's the first option in the list, then Whizard's suggestion would work fine... otherwise you just need to compare the current query row's value to whatever value it is you want selected (that part's not clear).

BTW you are using two different variables in that query: $row_folder_status and $row_folder... that will cause problems unless it is just a copy/paste error.