Dynamic combobox

A

Anonymous

Guest
Hello.I have a sample.It uses arrays but the ideea stays the same.All you have to do is to modify it

<select name="country" size="1" id="country">
<?
for ($i=0;$i<count($country_array);$i++)
{
if ($i==0)
{
?>
<option selected><?echo $country_array[$i]?></option>
<?
}
else
{
?>
<option><?echo $country_array[$i]?></option>
<?

}
}
?>
</select>
where
$country_array=array("France","Romania"); ans so on.
I hope you will understand this and then crezte your own.If not I'll try to send you the code for mysql :)
 
correction (you forgot to give the option's values.) also I would set a variable named $size before the loop. Doing this makes execution a lil faster. Updated code below

Code:
<select name="country" size="1" id="country">
<?
$size = sizeof($country_array);
for ($i=0; $i<$size;$i++)
{
if ($i==0)
{
?>
<option value = "<?echo $country_array[$i]?>" selected><?echo $country_array[$i]?></option>
<?
}
else
{
?>
<option value = "<?echo $country_array[$i]?>"><?echo $country_array[$i]?></option>
<?

}
}
?>
</select>
 
Back
Top