Re: Dynamically generate variable names?

From: Date: Thu, 26 Jul 2001 20:30:29 +0000
Subject: Re: Dynamically generate variable names?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-59825@lists.php.net to get a copy of this message
You want to use variable variables. You may have to play with this to get it to work exactly, but I would add a hidden field echo "<Input Type=Hidden Name=named value=\"$ai_info[0]\">"; That way $named = {The name of your checkbox} Then to access your checkbox just use ${$named} for example if ( ${$named} == 1) { echo "foo"; } Sheridan Saint-Michel Website Administrator FoxJet, an ITW Company www.foxjet.com ----- Original Message ----- From: Ian Marlier <ian@onepost.net> To: <php-general@lists.php.net> Sent: Thursday, July 26, 2001 2:55 PM Subject: [PHP] Dynamically generate variable names? > (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. > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#59825) next »