I have a page with two drop-downs, each listing the same employee names
and their id's as the values. So they look like:
<select name="selection _1">
<option value="12">Curl y</option>
<option value="8">Larry </option>
<option value="36">Moe</option>
</select>
....then further down the page:
<select name="selection _2">
<option value="12">Curl y</option>
<option value="8">Larry </option>
<option value="36">Moe</option>
</select>
Currently I am doing this, which works but seems sloppy:
<select name="selection _1">
<?
while($employee s=mysql_fetch_a ssoc($qry_rslt) ) {
/* ADD NAMES TO DROPDOWN WITH emp_id's AS THEIR VALUES */
?><option
value="<?=$empl oyees['emp_id']?>"><?=$employe es['name']?></option><?
/* CREATE ANOTHER ARRAY WITH THE emp_id AS THE KEY */
$emp_list_2[$employees['emp_id']]=$employees['name'];
}
?>
</select>
Then on the second drop-down:
<select name="selection _2">
<?
foreach($emp_li st_2 as $key => $emps) {
?>
<option value="<?=$key? >"><?=$emps?> </option>
<?
}
?>
</select>
Is there a better way to do this?
Thanks.
Steve.
and their id's as the values. So they look like:
<select name="selection _1">
<option value="12">Curl y</option>
<option value="8">Larry </option>
<option value="36">Moe</option>
</select>
....then further down the page:
<select name="selection _2">
<option value="12">Curl y</option>
<option value="8">Larry </option>
<option value="36">Moe</option>
</select>
Currently I am doing this, which works but seems sloppy:
<select name="selection _1">
<?
while($employee s=mysql_fetch_a ssoc($qry_rslt) ) {
/* ADD NAMES TO DROPDOWN WITH emp_id's AS THEIR VALUES */
?><option
value="<?=$empl oyees['emp_id']?>"><?=$employe es['name']?></option><?
/* CREATE ANOTHER ARRAY WITH THE emp_id AS THE KEY */
$emp_list_2[$employees['emp_id']]=$employees['name'];
}
?>
</select>
Then on the second drop-down:
<select name="selection _2">
<?
foreach($emp_li st_2 as $key => $emps) {
?>
<option value="<?=$key? >"><?=$emps?> </option>
<?
}
?>
</select>
Is there a better way to do this?
Thanks.
Steve.
Comment