Reputation: 839
I'm using the code below to return a list of LastNames into a form's drop down menu.
<?php
include 'conn.inc.php';
$sql_dropdown_lastname = "SELECT LastName FROM Individuals";
$sql_run_lastname = odbc_exec($conn_general, $sql_dropdown_lastname);
echo "<table><form action='index.php' method='POST'><tr><td>Individual Last Name</td><td><select name='IndivSurname'>";
while($lastname_row = odbc_fetch_array($sql_run_lastname)){
$AllLastName=$lastname_row['LastName'];
echo"<option value='$AllLastName'>$AllLastName</option>";
}
echo"</select></td>
</tr>
<tr>
<td><input type='submit' value='submit' name='submit'></td>
</tr>
</form>
</table>";
?>
However several entries are duplicate. How would I be able to eliminate any duplicates from the drop down list ?
Thanks in advance, J
Upvotes: 3
Views: 1736
Reputation: 2962
If they are truly duplicates (and not just people with the same last name), you can do it like this:
SELECT DISTINCT LastName FROM Individuals
Note, if they are people who are different, but have the same last name, you'd want to bring in another field in your query, such as this:
SELECT DISTINCT LastName, FirstName FROM Individuals
Upvotes: 5