I am fetching a field from a MySQL table, storing it in an arrray and then putting that array into a drop down menu with a for loop. The problem is that I am getting duplicate values. I tried using array_unique to remove the duplicate values and it didn't work. Maybe I'm not using it correctly. Here is the code that I have that is displaying duplicate values:
$query = "select * from readers2";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
echo '<form method=post action="results2.php">';
echo '<select name=searchterm>';
echo '<option></option>';
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
echo '<option>';
echo stripslashes($row['building']);
echo '</option>';
}
echo '</select>';
echo '<input type="submit" value="Go">';
echo '</form>';
Any ideas?
removing duplicate values from a mysql_fetch_array
Moderator: General Moderators
I have found the answer
$query = "select distinct building from readers2";