note 11585 modified in language.variables.variable by irchtml
| From: | irchtml@php.net | Date: | Tue, 24 Feb 2004 09:06:31 +0000 |
| Subject: | note 11585 modified in language.variables.variable by irchtml | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-65640@lists.php.net to get a copy of this message | ||
A good example of the use of variable variables name. Imagine that you want to modify at the same
time a list of more than one record from a db table.
1) You can easily create a dynamic form using PHP. Name your form elements using a static name and
the record id
ex: <input name="aninput<?php echo $recordid?>" which gives in the output
something like <input name="aninput15">
2)You need to provide to your form action/submit script the list of records ids via an array
serialized and urlencoded via an hidden field (to decode and un serialize once in the submit script)
3) In the script used to submit you form you can access the input value by using the variable
${'aninput'.$recordid} to dynamically create as many UPDATE query as you need
I used it for an intranet I'm building in my company and this is working great !
--was--
A good example of the use of variable variables name. Imagine that you want to modify at the same
time a list of more than one record from a db table.
1) You can easily create a dynamic form using PHP. Name your form elements using a static name and
the record id
ex: <input name="aninput<?php echo $recordid?>" which gives in the output
something like <input name="aninput15">
2)You need to provide to your form action/submit script the list of records ids via an array
serialized and urlencoded via an hidden field (to decode and un serialize once in the submit script)
3) In the script used to submit you form you can access the input value by using the variable
${'aninput'.$recordid} to dynamically create as many UPDATE query as you need
I used it for an intranet I'm building in my company and this is working great !
http://www.php.net/manual/en/language.variables.variable.php