greens85
10-21-2009, 04:48 PM
Hi all,
I'm currently retrieving some values from a database and placing them into a drop down box with the following code:
<select name="lea">
<option value="">-- Search All --</option>
<?php
$query = mysql_query("SELECT Leaname FROM schools ORDER BY Leaname ASC");
while ($result = mysql_fetch_array($query)) {
?>
<option value="<?php echo $result['Leaname']?>"><?php echo $result['Leaname']?></option>
<?php
}
?>
</select>
The problem is, because there is more than one instance of each value, the option box is returning something like this:
Value 1
Value 1
Value 1
Value 1
Value 1
Value 1
Value 2
Value 2
Value 2
Value 2
Value 3
Value 3
Value 3
Where as I only want it to show one instance of each, i.e.
Value 1
Value 2
Value 3
Is there a php workaround for this?
I know I could manually code the values into the html, but there are some many it would take a long time!
Thanks,
Greens85
I'm currently retrieving some values from a database and placing them into a drop down box with the following code:
<select name="lea">
<option value="">-- Search All --</option>
<?php
$query = mysql_query("SELECT Leaname FROM schools ORDER BY Leaname ASC");
while ($result = mysql_fetch_array($query)) {
?>
<option value="<?php echo $result['Leaname']?>"><?php echo $result['Leaname']?></option>
<?php
}
?>
</select>
The problem is, because there is more than one instance of each value, the option box is returning something like this:
Value 1
Value 1
Value 1
Value 1
Value 1
Value 1
Value 2
Value 2
Value 2
Value 2
Value 3
Value 3
Value 3
Where as I only want it to show one instance of each, i.e.
Value 1
Value 2
Value 3
Is there a php workaround for this?
I know I could manually code the values into the html, but there are some many it would take a long time!
Thanks,
Greens85