omen Posted August 8, 2008 Share Posted August 8, 2008 Hi, I am trying to clean up some code by enclosing common elements in a loop. There are 20 input boxes for inputing pictures, which can be set up in a loop, but I can't get it to work. Original code: <tr> <td class="h3"><strong><?php echo _IMAGE1;?></strong></td> </tr> <tr> <td width="33%" valign="top"> <?php echo _CATEGORY_DEFCONTENT;?><input class="inputbox" type="text" name="image1desc" size="40" value="<?php echo $row->image1desc;?>"/> <?php imageUpload($row->image1,'1',$list['image1'],'image1');?> </td> </tr> <tr> <td class="h3"><strong><?php echo _IMAGE2;?></strong></td> </tr> <tr> <td width="33%" valign="top"> <?php echo _CATEGORY_DEFCONTENT;?><input class="inputbox" type="text" name="image2desc" size="50" value="<?php echo $row->image2desc;?>" /> <?php imageUpload($row->image2,'1',$list['image2'],'image2');?> </td> </tr> This is what I came up with so far: <?php for ($picnumber=1; $picnumber<=2;$picnumber++){ ?> <tr> <td class="h3"><strong><?php echo _IMAGE.$picnumber;?></strong></td> </tr> <?php echo $picnumber; ?> The problem is that "_IMAGE.$picnumber" is beeing displayed as "_IMAGE1" but it should have been replaced by a string value in _IMAGE1, _IMAGE2, etc in a language file. How will I get it to work? Thank you Link to comment https://forums.phpfreaks.com/topic/118821-cant-concatenate-text-to-parse-properly/ Share on other sites More sharing options...
DarkWater Posted August 8, 2008 Share Posted August 8, 2008 Is _IMAGE1 a constant? Along with _IMAGE2? If they are...check out the constant() function. Link to comment https://forums.phpfreaks.com/topic/118821-cant-concatenate-text-to-parse-properly/#findComment-611826 Share on other sites More sharing options...
omen Posted August 8, 2008 Author Share Posted August 8, 2008 Indeed both were constants, constant() worked, Here is the working code: <?php for ($picnumber=1; $picnumber<=3;$picnumber++){ ?> <tr> <td class="h3"><strong><?php echo constant(_IMAGE.$picnumber);?></strong></td> </tr> <?php echo $picnumber; ?> It should be easy from now on, thank you for your help. Link to comment https://forums.phpfreaks.com/topic/118821-cant-concatenate-text-to-parse-properly/#findComment-611844 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.