I have a form in which there is a dropdown list. this list is populated with values from the database. But, when I submit the form, the dropdown list gets duplicate values.
code -
<form name="form1" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<select name="test">
<?php
GetList();
?>
</select>
<input type="submit" value="submit" class="submit" />
</form>
my GetList
function -
function GetList()
{
global $db;
$sql = "SELECT id,text FROM table";
$result = mysql_query ($sql);
while($nt=mysql_fetch_array($result))
{ //Array or records stored in $nt
echo '<option value='.$nt[id].'>'.$nt[text].'</option>';
}
}
The dropdown list should be populated only once. I dont mind if the dropdown list is re-populated on form post but I dont want duplicate values in my dropdown list?
How do I get rid of the duplicate values?
edit - For e.g - if the dropdown displays values 1,2,3,4 when I first land on the page. After, i click submit, the dropdown list displays 1,2,3,4,1,2,3,4. And goes on that way as many times as I submit.