This is not working for me, I am trying to populate drop down box from one table in database, and get some info from another table to show selected ...
If anyone can help me out here ,that would be great..
Table name where category are = classcategory
Table name where trying to fill in the selected = tools
<form action="maintest2.php" method="POST">
<table border="0" cellpadding="2" width="100%">
<tr>
<td><b>Main Category:</b></td>
<td><?
$query = "SELECT id, cats FROM tools where status1='1' and id='1'";
$result = mysql_query($query) or die('Error, query failed');
while ($myrow = mysql_fetch_array($result)) {
$cate=$myrow["cats"]; //need this as the selected option
}
$sql="SELECT category FROM classcategory ORDER by category";
$result=mysql_query($sql);
$options="";
while ($row=mysql_fetch_array($result)) {
//$id=$row["id"];
$category=$row["category"];
$selected = ($cate) ? ' selected="selected"' : '';
$options.="<OPTION VALUE=\"$category\"$selected>".$category;
}
?>
<SELECT NAME=category>
<OPTION VALUE=0>Choose
<?=$options?>
</SELECT>
</td>
</tr>
<tr><td colspan=2><input type="submit" name="submit" value="submit"></td></tr>
</table>
</form>