I've been trying to figure this out for the past couple of days, but I'm stumped. I'm writing a simple function that will create a select box for an HTML form using data from a mysql database. I want to be able to give the function 3 variables and have it create the options for the select. Here is what I have so far
PHP Code:
function select_values($table,$visible,$id){
$query = sprintf("SELECT * from $table");
$result = mysql_query($query);
query_check($result);
$visible = strtoupper($visible);
$id = strtoupper($id);
while($row = mysql_fetch_assoc($result)){
$id = $row['$id'];
$visible = $row['$visible'];
echo "<option value=\"$id\">$visible</option>\n";
}
exit;
}
And here is the call to it in my page
PHP Code:
<?php select_values(MB,MB_DESC,MB_ID);?>
The echo statement works except the variables do not display. I get this
<option value=""></option>
in the source of my document.
If I replace $id and $visible with MB_ID and MB_DESC inside the function it works flawlessly.
Thanks for you help