How to show selected value of dropdown list from database in php
<p>How do I show the selected value of a dropdown list from my mysql database. The dropdown list is dependent to my <code>Category</code> dropdown list. These are the codes:</p>

<pre><code>&lt;?php $id = $_GET["id"];
if(!$pupcon){
    die(mysql_error());
}
mysql_select_db($database_pupcon, $pupcon);

$getDropdown2 = mysql_query("select * from tblitemname where CategoryID = $id");
    while($row = mysql_fetch_array($getDropdown2)){
        echo "&lt;option value=\"".$row["ItemID"]."\"&gt;".$row["Item_Name"]."&lt;/option&gt;";
    }   ?&gt;
</code></pre>

<p>Here are the codes for the first dropdown list (<code>Category</code>) which populates the <code>Item Name</code> dropdown.</p>

<pre><code>&lt;select name="Category" id="Category" class="field select large" onChange="loadXMLDoc(this.value);"&gt;
                                &lt;?php do {  ?&gt;
                                &lt;option value="&lt;?php echo $row_Recordset1['CategoryID']?&gt;"&lt;?php if (!(strcmp($row_Recordset1['CategoryID'], $row_editRecordset['CategoryID']))) {echo "selected=\"selected\"";} ?&gt;&gt;&lt;?php echo $row_Recordset1['CategoryName']?&gt;&lt;/option&gt;
                                &lt;?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); $rows = mysql_num_rows($Recordset1); if($rows &gt; 0) {
  mysql_data_seek($Recordset1, 0);
  $row_Recordset1 = mysql_fetch_assoc($Recordset1);}?&gt;
                            &lt;/select&gt;
</code></pre>
