I have read quite a few posts on how to do this (Retain Selected Value PHP Dynamic Drop Down List), but cannot quite understand what to do. What I have works, but it does not retain the selected. Any help appreciated.

<form action="" method="POST" name="form1" id="form1">
<select name="selClass" size="1" id="selClass" onchange="form1.submit()">
<option value="">Select a class</option>
echo "<option value='" . "All records" . "' . >" . "all records" . "</option>";
while ($row1 = mysqli_fetch_array($rs5)) {
echo "<option value='" . $row1["class"] . "'>" . $row1["class"] . "</option>";

Sorry, I'm a little confused by what you mean. What do you mean by retain the selected value? When do you want it to retain the value? After submitting the form?

A dropdown will default to the option that has selected specified. So, for example, when iterating through the while loop, if $row1['class'] is equivalent to what was passed into the form, for example $_POST['selClass'], then you would want to set it to be selected as so: <option value="value" selected>.