How do I use a string's contents as a variable name?
Posted: Wed Jun 15, 2005 9:57 am
Here is a small portion of the code I have. I have cut out all of the in-between code and most html formatting provided by the code to get to the meat of the issue:
A form is created dynamically using the fields available from a table. I'll assume one field to eliminate the for loop.
When the form is submitted a value is assigned to $ID. How do I display this value using an echo statement?
A form is created dynamically using the fields available from a table. I'll assume one field to eliminate the for loop.
Code: Select all
$fields = mysql_list_fields($dbname, $table, $link);
$i = 0;
$field_arrayї$i] = mysql_field_name($fields, $i);
print "e;<input type=text name=$field_arrayї$i]>"e;;
//Let's say it generates a text field with the name=ID.Code: Select all
echo $ID;
//This works, but I won't always know the
//name of the form field since it's created dynamically
$form_arrayї$i] = "e;$"e;. $field_arrayї$i];
$str = $form_arrayї$i];
echo $form_arrayї$i];
echo $str;
//This outputs "e;$ID$ID"e; instead of the value
$str2 = $field_arrayї$i];
echo $field_arrayї$i];
echo $str2;
//This outputs "e;IDID"e; instead of the value.