echo '<tr><td>' . _('Item Sub Category') . ':</td><td><select name="CategoryID">';
 //
  
 $sql = 'SELECT stockmaincategoryid, stockmaincategoryname FROM stockmaincategory';
 $ErrMsg = _('The stock categories could not be retrieved because');
 $DbgMsg = _('The SQL used to retrieve stock categories and failed was');
 $result = DB_query($sql,$db,$ErrMsg,$DbgMsg);

while ($myrow=DB_fetch_array($result))
{
	if (!isset($_POST['CategoryID']) or $myrow['stockmaincategoryid']==$_POST['stockmaincategoryid']){
		echo '<option selected VALUE="'. $myrow['stockmaincategoryid'] . '">' . $myrow['stockmaincategoryid'].'</option>';
	} 
	else {
		   echo '<option VALUE="'. $myrow['stockmaincategoryid'] . '">' . $myrow['stockmaincategoryid'].'</option>';
	}
}
