database filled select form issue.

admin

Administrator
Staff member
Greetings!

Back again with another one of my brain buster questions.

I am currently propagating a select form drop down list with database driven elements like so:

<?
$sql = "SELECT item FROM types ORDER BY item ASC";
$connection = mysql_connect("localhost", "user", "pass")
or die ("Couldn't connect to server.");
$db = mysql_select_db("db", $connection)
or die ("Couldn't select database.");
$sql_result = mysql_query($sql)
or die("Couldn't execute query.");
if (!$sql_result) {
echo "<P>Could not generate list!";
} else {
echo "
<select name=\"sel_record\">
<option value=http://www.phpbuilder.com/board/archive/index.php/\"\"> -- Select Item -- </option>
";
while ($row = mysql_fetch_array($sql_result)) {
$item = $row["item"];
echo "<option value=\"$item\">$item</option>";
}
echo "</select>";
}
?>

While all that seems fine and dandy, if "item" has two of the same things listed on different rows, then a duplicate entry is presented. Is there any way around this to where when the query is returned, it filters out duplicate entries before sending them to the drop down list?
 
Back
Top