[BNM] dynamically creating variable names
Ali
ali at nubz.com
Fri Sep 15 10:54:46 BST 2006
I believe the variable name you are looking for is ${"mp3title".$x} where x is the current iteration of your loop to process the input.
hth
Ali
----- Original Message -----
From: delarge
To: Brighton New Media
Sent: Friday, September 15, 2006 10:03 AM
Subject: [BNM] dynamically creating variable names
What's the deal BNM?
I am working on an admin area for a discography. There can be up to 15 mp3
clips for each release.
Rather than manually write out mp3clip1, mp3clip2 etc. I was getting down
with a for loop like so for writing out the inital form:
$tracktotal = 15;
for($x=0;$x<$tracktotal;$x++){
?>
<div><input name="mp3title<? echo $x;?>" type="text" id="mp3title<? echo
$x;?>" size="50" /></div>
<div><input name="mp3file<? echo $x;?>" type="text" id="mp3file<? echo
$x;?>" size="50" /></div>
<hr />
<?
// end of for loop
}
?>
Works fine for the 'add an item' bit...
BUT - when it comes to an 'amend' form where the fields have to be
prepopulated, woe is abound....
The won't work. I am trying to create the variable name... but of course the
script takes $mp3title as a variable - which has no value, so I just get the
number...
$tracktotal = 15;
for($x=0;$x<$tracktotal;$x++){
?>
<div><input name="mp3title<? echo $x;?>" type="text" id="mp3title<? echo
$x;?>" value="<? echo $mp3title."".$x;?>" size="50" /></div>
<div><input name="mp3file<? echo $x;?>" type="text" id="mp3file<? echo
$x;?>" value="<? echo $mp3file."".$x;?>" size="50" /></div>
<hr />
<?
// end of for loop
}
?>
How can I get away from the script taking $mp3title and $mp3file as
variables and waiting until they've had that number slapped on the end?
Thanks a lot!
--
Paul Burgess
http://delarge.co.uk
http://streetstickers.co.uk
http://iampaulburgess.co.uk
--
BNM info/subscription/archives: http://www.brightonnewmedia.org/
BNM archive search: http://www.roddis.org/bnm/search.php
BNM Del.icio.us tag: http://del.icio.us/tag/bnm/
BNM Flickr group: http://www.flickr.com/groups/bnm/
BNM powered by http://www.screen-play.net/
--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.0.405 / Virus Database: 268.12.4/448 - Release Date: 14/09/2006
More information about the BNMList mailing list
BNMList is hosted by Screenlists, a Screen-Play.net service