i'm populating a select menu from mySQL using this code:
$sql = "SELECT * FROM products order by printer";
$result = mysql_query($sql) or die(mysql_error());
// Counts the number of rows
$num_rows=mysql_num_rows($result);
// Tests if the database is empty
if ($num_rows == 0) {
//if select menu is empty
}
// If there are records....
else {
// Form to pick the product to be ammended
echo "<div align=\"center\">";
echo "<FORM method=post action=\"\">";
echo "Please select a printer to check for matching cartridges<BR>";
echo "<select name=\"printer\">";
// Loop to populate the menu
while ($row=mysql_fetch_array($result)) {
$printer=$row["printer"];
$brand=$row["brand"];
$code=$row["code"];
$productid=$row["productid"];
// Display options in the pulldown box
echo "<option value=\"$productid\">$printer</option>";
} // end while
echo "</select>";
} // end else
echo "<BR><BR>";
echo "<input type=\"submit\" value=\"View the item\"></FORM>";
echo "</div>";
The problem is that the var that i am retrieving, the name of the printer the cartridge fits, occurs multiple times in the table. How can i make it so that each printer is only entered into the select menu once?
Thanks.