View Full Version : list box initial select

12-28-2005, 07:26 PM
i have this code which produces a list box dependent on items in a table in my database. i am creating an update page and need this list box to show the inital selected item dependent on the record in the database.

the code for the list box is

<? $query="SELECT catagory FROM catagory order by catagory asc";

$result = mysql_query ($query);
echo "<select name=catagory>Catagory</option>";
// printing the list box select command

while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
echo "<option value=$nt[catagory]>$nt[catagory]</option>";
/* Option values are added by looping through the array */
echo "</select>";// Closing of list box

The record that are able to be updated are stored in a table called directory. this table has a catagory column. but when a new record is added the catagory is selected from a list box populated by the catagory table from the database. any suggestions on how i would add an initial selected item into the above code.

I have other list boxes with inital selections like:

<select name="start">
<option value="Jan">Jan</option>
<option value="Feb">Feb</option>
<option value="Mar">Mar</option>
<option value="Apr">Apr</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="Aug">Aug</option>
<option value="Sept">Sept</option>
<option value="Oct">Oct</option>
<option value="Nov">Nov</option>
<option value="Dec">Dec</option>
<option value="<?php echo($start) ?>" selected>
<?php echo($start) ?>

Thanks in advance.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum