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 <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
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
>
>
>
> --
>
> [EMAIL PROTECTED]
> 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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to