RE: [PHP] Re: Changing variable names in a while loop

From: Date: Fri, 28 May 2004 13:02:07 +0000
Subject: RE: [PHP] Re: Changing variable names in a while loop
Groups: php.general 
Request: Send a blank email to php-general+get-187116@lists.php.net to get a copy of this message
On 28 May 2004 12:30, Torsten Roehr wrote: > "I.A. Gray" <tech@selectperformers.com> wrote in message > news:GKENIOKKDEHBGNGOCJHNEEGBCGAA.tech@selectperformers.com... > > Hi all, > > > > Easy question (I hope). My brain seems not be working today, so > > could someone help me with this one? [...] > > How can I get the value to change in each form? The name and id > > for each input field will change from (for example) fcomposer1 to > fcomposer30 but > how > > do I change the value for each input to show the variables taken > > from the database which will be $composer1 to $composer30 ? > > Obviously if I put in $composer$countything that will just output > > the value of $composer followed by the value for $countything, but > > I want it to output the value for $composer1 if $countything=1 or > > $composer10 if $countything=10 . Is there something I can do with > > variable variables? I couldn't see > any examples > in > > the PHP manual. > > What you want is this: > $temp = 'composer' . $countything; > Then use ${$temp} -> it will efectively be $composer1. You can also write this as ${'composer'.$countything} But I'd really, really suggest looking into using arrays for this -- it looks much more like an array-ish problem than a variable-variable-ish problem to me. Using arrays, your input fields would look like: <input name='fcomposer[$countything]' type='text' size='20' maxlength='60' /> and then your processing code can easily address $fcomposer[$countything] etc. Cheers! Mike --------------------------------------------------------------------- Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Headingley Campus, LEEDS, LS6 3QS, United Kingdom Email: m.ford@leedsmet.ac.uk Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211

« previous php.general (#187116) next »