RE: [PHP] Dynamic Variable Creation from Forms

From: Date: Thu, 01 Feb 2001 00:50:49 +0000
Subject: RE: [PHP] Dynamic Variable Creation from Forms
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-37575@lists.php.net to get a copy of this message
have you thought about creating an array of the variables? "chk[$row]" and then you'd read 'em back like chk["aaa"] or chk["bbb"] or you could loop through the array with a each statement... but for variable variables...try ${"chk_".$row}["field"] which should work... -Jonathan Sharp Director of Technology - Imprev Inc. Renwick Development Group - Flyerware http://www.flyerware.com/ Phone: (425)688-9200 Cell: (425)766-1398 EPage: 4257661398@page.nextel.com -----Original Message----- From: [ rswfire ] [mailto:rswfire@hotmail.com] Sent: Wednesday, January 31, 2001 4:41 PM To: php-general@lists.php.net Subject: Re: [PHP] Dynamic Variable Creation from Forms Thanks for your response, but that's not my problem. I'll explain further... I have a table with the following fields in a row: aaa bbb ccc ddd eee I have a page with a form: <FORM POST> mysql_db_query($db, "SELECT * FROM table"); while ($row = mysql_fetch_array($result)) { echo "<INPUT TYPE='CHECKBOX' NAME='chk_".$row["checkboxtype"]."'>"; } This will create several checkboxes with the following names: chk_aaa chk_bbb chk_ccc chk_ddd chk_eee ON THE NEXT PAGE, AFTER THE SUBMIT BUTTON IS CLICKED, THESE VARIABLES WILL EXIST, but I cannot refer to them like this: $chk_$row["field"] How can I refer to them??? They can change based on the field data, so they cannot be considered static variables. Not *sure* i understand the problem, but this may be the solution: $foo = "hello"; $bar = "foo"; $foobar = $$bar; $foobar now contains "hello". Gfunk - http://www.gfunk007.com/ I sense much beer in you. Beer leads to intoxication, intoxication to hangovers, and hangovers to... suffering. ----- Original Message ----- From: "[ rswfire ]" <rswfire@hotmail.com> To: <php-general@lists.php.net> Sent: Thursday, February 01, 2001 11:28 AM Subject: [PHP] Dynamic Variable Creation from Forms >I have a problem I'm not sure how to fix. > >PART I > >I have a form on a page that creates its variables dynamically. Here's an >example: > >mysql_db_query($db, "SELECT * FROM table"); >while ($row = mysql_fetch_array($result)) >{ > > echo "<INPUT TYPE='CHECKBOX' > NAME='chk_".$row["checkboxtype"]."'>"; > >} > >PART II > >I need to make reference to these dynamically created variables. How do I >do this? This does not work, obviously: > >$chk_.$row["checkboxtype"] > >Thanks in advance... _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com -- 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 (#37575) next »