Code: Select all
<select name="comp" id="comp" style="width:130px;">
<?php $sqlcomp = mysql_query("SELECT * FROM comp");
while ($redcomp = mysql_fetch_array($sqlcomp)) {
extract($redcomp);
echo "<option value=\"$comp_id\">comp_name</option>";
}
?>
</select>
Ex :
Results from database are :
comp_id comp_name
1 comp1
2 comp2
3 comp3
and in session I have stored $_SESSION['comp_id'] equals 2 ; now I'd like to get the following result in html from php :
Code: Select all
<select name="comp" id="comp" style="width:130px;">
<option value="2">comp2</option>
<option value="1">comp1</option>
<option value="3">comp3</option>
</select>
Code: Select all
<select name="comp" id="comp" style="width:130px;">
<option value="2">comp2</option>
<option value="3">comp1</option>
<option value="1">comp3</option>
</select>