I have a form which I am using to filter a recordset. It all works as I want, but for one small annoying thing - there is an empty space at the top of the list of options (see screenshot). How can I get rid of this empty option?

empty_option.jpg

I have checked the recordset which is used to generate the options for the dropdown list and this is OK, i.e. correct number of options.

<?php
$con=mysqli_connect("localhost","jtwiname");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$query_rs5 = "SELECT distinct class FROM classname";
$rs5 = mysqli_query($con, $query_rs5)or die( mysqli_error($con) );
$row1 = mysqli_num_rows($rs5);
?>

The drop down menu.

<form action="" method="POST" name="form1" id="form1">
<select name="selClass" size="1" id="selClass" onchange="form1.submit()">
<option value="All records">All records</option>
<?php
do {  
?> 
<option value="<?php echo $row1['class']?>" <?php if($_POST['selClass'] == $row1['class']) echo 'selected="selected"' ?>><?php echo $row1['class']?></option>
<?php
} while ($row1 = mysqli_fetch_assoc($rs5));
?>
  </select>
</form>

Any help would be greatly appreciated.

It looks like there are rows in the database in which the value of the class field is empty or null.

You can adjust your query to be SELECT DISTINCT class FROM classname WHERE class <> '' AND class IS NOT NULL

Thanks duweihan For This Information..