I've created a drop down list that dynamically gets its <option> values from a MySQL database. The "business" column that populates this drop down menu does not have a value for every record in the database. It is a column for business name, but not all of our clients are business owners, so it is left blank.
My problem is I do not want the blank column entries to appear in the drop down menu. Right now, I have the menu values sorted alphabetically by business name, so at the top are all of the blank entries - about 5 blank lines - and then the first business name appears.
Here is the code I am currently using:
<select name="searchbusiness">
<?php
$query = mysql_query("select business from customers order by business");
if(!$query){
die('Invalid query:'.mysql_error());
}
$num_results = mysql_num_rows($query);
for($i=0; $i<$num_results; $i++){
$row = mysql_fetch_assoc($query);
?>
<option><?php echo stripslashes($row['business']); ?></option>
<?php } mysql_free_result($query); ?>
</select>
How can I remove the blank entries from the drop down list?