I'm in the process of putting together a PHP/mySQL form with only basic knowledge of both. For the first drop-down list on the form, I'd like to pull the options from a mySQL database. I've set this up as follows:
<?php
$query = "SELECT * FROM test";
$result = mysqli_query($link , $query);
?>
Select your group number:
<select name="group">
<?php
while ($line = mysqli_fetch_array($result, MYSQL_ASSOC)) {
?>
<option value="<?php echo $line['group'];?>"><?php echo $line['group'];?></option>
<?php
}
?>
</select>
However, this returns each group value even when they're identical, so I end up with duplicates (FIGURE 1). I'd like to group all like values (FIGURE 2).
I understand using GROUP BY might accomplish this, but when I include GROUP BY in my code as follows, my drop-down just ends up empty.
$query = "SELECT * FROM test GROUP BY group";
Am I making a mistake with my use of GROUP BY?
NOTE: "group" is the id of the column I'm fetching.