Changing variable names in a while loop

From: Date: Fri, 28 May 2004 10:24:17 +0000
Subject: Changing variable names in a while loop
Groups: php.general 
Request: Send a blank email to php-general+get-187105@lists.php.net to get a copy of this message
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> <td><input name='fcomposer$countything' type='text' id='fcomposer$countything' size='20' maxlength='60'/></td> <td><input name='fsubheading$countything' type='text' id='fsubheading$countything' size='20' maxlength='80' /></td> <td><input name='fmovementno$countything' type='text' id='fmovementno$countything' size='3' maxlength='3' /></td> <td><input name='ftracktitle$countything' type='text' id='ftracktitle$countything' size='20' maxlength='60' /></td> <td><input name='ftracksubtitle$countything' type='text' id='ftracksubtitle$countything' size='20' maxlength='80' /></td> <td><input name='ftracklength$countything' type='text' id='ftracklength$countything' size='5' maxlength='8' /></td> <td><input 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. Many thanks, Ian Gray

« previous php.general (#187105) next »