Dynamically generate variable names?

From: Date: Thu, 26 Jul 2001 19:55:23 +0000
Subject: Dynamically generate variable names?
Groups: php.general 
Request: Send a blank email to php-general+get-59819@lists.php.net to get a copy of this message
(please reply to me as well as the list, as I'm not subscribed) I'm trying to generate variable names dynamically, based on information read from a MySQL database. When a user creates an account, they're asked to choose from a list of groups to which they belong (by clicking checkboxes in an HTML form). This list is generated in real-time from the database. Each group's checkbox is given a name based on their group id number, which works fine. (The code looks like this, ai_info[0] is the group ID number: while ($ai_info = mysql_fetch_array ($academic_interest_result)){ if ($ai_counter==0) { echo "<tr>"; echo "<td width=\"37\" bgcolor=\"white\" align=\"right\">"; echo "<input type=\"checkbox\" name=\"$ai_info[0]\" value=\"1\">"; echo "</td>"; echo "<td width=\"230\" bgcolor=\"white\" align=\"left\">"; echo $ai_info[1]; echo "</td>"; $ai_counter = 1; } else { echo "<td width=\"37\" bgcolor=\"white\" align=\"right\">"; echo "<input type=\"checkbox\" name=\"$ai_info[0]\" value=\"1\">"; echo "</td>"; echo "<td width=\"230\" bgcolor=\"white\" align=\"left\">"; echo $ai_info[1]; echo "</td></tr>"; $ai_counter = 0; } } ) So that part is cool. The question comes when the form of which these are part is submitted. A seperate page processes the results. I need it to access the database, generate a list of the group id's (using the same fetch_array syntax), create a variable name, and then check if that variable is == 1. Does that make sense? So if, on the first page, someone submits the form with group id 293 checked, a variable $293==1 is passed to the data processing page. WHat I need to do is generate the variable $293 on the second page (from the string "$" and the database value "293") so that I can use it in an if statement. Any thoughts? Okay, I hope that made sense.... - Ian -- ian@onepost.net 773 667 2550 Eventually all things merge into one, and a river runs through it. The river was cut by the world's great flood and runs over rocks from the basement of time. On some of the rocks are timeless raindrops. Under the rocks are the words, and some of the words are theirs. I am haunted by waters.

« previous php.general (#59819) next »