I have been struggling for several days with this and I know its gonna be a simple solution or somehow I am not seeing the problem.
I have a drop Down Menu (Column AP) at http://aguy.us/tsw/admin/AbilityInsert.php which I am trying to call a Function dropdownmenu.
In trying to condense the code on the AbilityInsert.php page I realized I could take the repeated code for each of the Drop downs and use a function.. Currently all the menus work on the page with the exception of the AP Column, which is my Function Dropdownmenu experiment. The others are hard coded into the page until I get the function working properly.
The AP drop down is utilizing the Function dropdownmenu below with 5 variables. The first 3 variables seem to work as intended. The drop box title is AP fine and the name of the select is appropriately "ID_AP"
Inspect Element return
<td>AP<br> <select size="1" name="ID_AP">
<option selected="selected"></option>
<option value=""></option>
<option value=""></option>
<option value=""></option>
<option value=""></option>
<option value=""></option>
<option value=""></option>
<option value=""></option>
<option value=""></option>
<option value=""></option>
</select></td>
but if I use $option1 and $option2 in the following line of the function
print "<OPTION VALUE={$row['".$option1."']}>{$row['".$option2."']}</option>";
the Drop down returns empty but with the appropriate amount of iterations just blank.
If I change that line and hard code the line with the following
print "<OPTION VALUE={$row['ID_AP']}>{$row['ActPass']}</option>";
the drop box returns all the AP table contents for the appropriate rows.
If I use the hard coded line It defeats the purpose of the function.. To reduced repeated code. Since i have 9 of these drop downs on this page alone all pulling from separate SQl tables it would be awesome if I could just call a function with differing variables for each drop-down.
Function being called in the page with its variables:
dropdownmenu(AP, ActPass, ID_AP, 'ID_AP','ActPass');
Function Code:
//function that returns drop down menus from variious sql tables
function dropdownmenu($table, $ordby, $n, $option1, $option2 ) {
//.$table. DROP DOWN
$sql2 = 'SELECT * FROM `'.$table.'` ORDER BY `'.$table.'`.`'.$ordby.'` ASC LIMIT 0, 30 ';
$result=mysql_query($sql2) or die(mysql_error());
if($r =mysql_Query($sql2)) {//run Query
$i=0;
//Retrieve Records and Print .$table. Drop down box
print "<td>".$table."</br> <SELECT SIZE='1' NAME= '".$n."'>";
print "<option selected=\"selected\"></option>";
while (($row =mysql_fetch_array($result)) !==False){
$i++;
print "<OPTION VALUE={$row['".$option1."']}>{$row['".$option2."']}</option>";
}
print "</SELECT></td>";
}
}
So where has my function theory broken down. I am really stumped and have tried many variations in syntax, I have googled but apparently my google foo is not, I have pounded my head on my table and well I am apparently just now seeing my incorrect coding....
Help!