[Newbie] Code does not work as Function. Help!
Posted: Fri Oct 24, 2008 6:08 am
Hello I have created some code to Fill a HTML select box from MySQL data, the DATA is already loaded into an array this code makes it unique, sorts it and prints it. when this not used as a function it works fine. My problem is a have 7 select boxes and i have the code written 7 times, with only two variable names changed. So i intend to optimise into a function but I'm stuck I cannot get it to work. This is the function.
and this is the select box code:
This only outputs 1 result, when there should be 5 (for this 'RadMan') so its clearly not looping but i do not understand why. Please Help.
Thanks in advance. Brendan
Code: Select all
function fillInSelect($si){
$makeUnique = array();
do {
$makeUnique[].=$si;
}
while ($row_all_radioProducts = mysql_fetch_assoc($all_radioProducts));
$makeUnique=array_unique($makeUnique);
natcasesort($makeUnique);
foreach ($makeUnique as $value) {
echo "<option value=" . "\"" . $value ."\"";
if($value == $check_RadMan){echo " selected=\"selected\"";}
echo ">" . $value ."</option>\n";
$rows = mysql_num_rows($all_radioProducts);
if($rows > 0) {
mysql_data_seek($all_radioProducts, 0);
$row_all_radioProducts = mysql_fetch_assoc($all_radioProducts);
}}
}Code: Select all
<select name="selectRadMan" id="selectRadMan">
<option value="ALL" <?php if($check_RadMan == "ALL"){echo "selected=\"selected\"";} ?>>Manufacturer (All)</option>
<?php fillInSelect($row_all_radioProducts['RadMan']); ?>
</select>Thanks in advance. Brendan