note 11585 modified in language.variables.variable by philip

From: Date: Wed, 16 Mar 2005 01:23:42 +0000
Subject: note 11585 modified in language.variables.variable by philip
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-86525@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 [Editor Note: Simply use an array instead, for example: <input name="aninput[<?php echo $recordid?>]" And loop through that array. -Philip] --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://php.net/manual/en/language.variables.variable.php

« previous php.notes (#86525) next »