Forum Moderators: coopster

Message Too Old, No Replies

removing duplicate values from a mysql_fetch_array

Using PHP and MySQL

         

jrawson

8:24 pm on Mar 10, 2004 (gmt 0)

10+ Year Member



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?

justageek

8:41 pm on Mar 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try this since all you seem to want is building:

$query = "select distinct building from readers2";

JAG

jrawson

8:50 pm on Mar 10, 2004 (gmt 0)

10+ Year Member



That did it, thanks a bunch!