Hi everybody!
I made a function which automatically creates a combo box with values. I am still a beginner so this might not be the best way. The idea is that I only need to define a few variables to make a combo box.
An example would be lib_survey_combo("cbo_test", "width:100px;", "tbl_test", "test_id", "test_name"
. This all looks very nice, but there is a problem:
To actually make this work I should put $test_id instead of $id_field and $test_name instead of $field. But since I want this function to work in other cases too this isn't a solution. Does anybody know what I should do to actually make this work. Is there another way to do this. Thanks a lot!
I made a function which automatically creates a combo box with values. I am still a beginner so this might not be the best way. The idea is that I only need to define a few variables to make a combo box.
An example would be lib_survey_combo("cbo_test", "width:100px;", "tbl_test", "test_id", "test_name"
Code:
function lib_survey_combo($name, $style, $table, $id_field, $field){
/*===============================================================================
Function which creates a combo box with values
===============================================================================*/
echo "<select name=\"$name\"";
if (!empty($style)){ echo "style=\"$style\""; }
echo "><option>--select--</option>";
$query = "SELECT * FROM $table ORDER BY $field;";
$result = mysql_query($query);
$n_messages = mysql_num_rows($result);
while ($data=mysql_fetch_array($result)) {
extract($data);
echo "<option value=\"[b]$id_field[/b]\">[b]$field[/b]</option>";
}
echo "</select>";
}
To actually make this work I should put $test_id instead of $id_field and $test_name instead of $field. But since I want this function to work in other cases too this isn't a solution. Does anybody know what I should do to actually make this work. Is there another way to do this. Thanks a lot!