Jump to content

Can't concatenate text to parse properly


omen

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.