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

2004-05-28 Thread I.A. Gray
Thanks, Torsten. That clears things up quite a bit.  I do find the PHP
manual a little heavy going sometimes.  Does this mean then that I have to
do this:
$tempcomposer = 'composer' . $countything;
$tempsubheading = 'subheading' . $countything;
$tempmovementno = 'movementno' . $countything;

etc...

as I have about 8 variables to change?

Best wishes,

Ian Gray


-Original Message-
From: Torsten Roehr [mailto:[EMAIL PROTECTED]
Sent: 28 May 2004 12:30
To: [EMAIL PROTECTED]
Subject: [PHP] Re: Changing variable names in a while loop


I.A. Gray [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Hi all,

 Easy question (I hope).  My brain seems not be working today, so could
 someone help me with this one?

 I have a while loop outputting part of an html form which inputs track
 information for CDs:

  $countything = 1;
   while ($countything !=31) {
   echo 
   tr
 td$countything./td
 tdinput name='fcomposer$countything' type='text'
 id='fcomposer$countything' size='20' maxlength='60'//td
 tdinput name='fsubheading$countything' type='text'
 id='fsubheading$countything' size='20' maxlength='80' //td
 tdinput name='fmovementno$countything' type='text'
 id='fmovementno$countything' size='3' maxlength='3' //td
 tdinput name='ftracktitle$countything' type='text'
 id='ftracktitle$countything' size='20' maxlength='60' //td
 tdinput name='ftracksubtitle$countything' type='text'
 id='ftracksubtitle$countything' size='20' maxlength='80' //td
 tdinput name='ftracklength$countything' type='text'
 id='ftracklength$countything' size='5' maxlength='8' //td
 tdinput name='fextrainfo$countything' type='text'
 id='fextrainfo$countything' size='20' maxlength='80' //td
   /tr\n;
 $countything++;
 }


 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.

Take a look here:
http://de2.php.net/manual/en/language.variables.variable.php

Regards, Torsten Roehr

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2004-05-28 Thread Torsten Roehr
I.A. Gray [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Thanks, Torsten. That clears things up quite a bit.  I do find the PHP
 manual a little heavy going sometimes.  Does this mean then that I have to
 do this:
 $tempcomposer = 'composer' . $countything;
 $tempsubheading = 'subheading' . $countything;
 $tempmovementno = 'movementno' . $countything;

 etc...

 as I have about 8 variables to change?

I think so, yes. Just put them into your loop and then use ${$tempcomposer}
and so on to put the value into your input value attribute.

Regards, Torsten

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



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

2004-05-28 Thread Ford, Mike [LSS]
On 28 May 2004 12:30, Torsten Roehr wrote:

 I.A. Gray [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
  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: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php