Jump to content

displaying $row->name in a for loop


omen

Recommended Posts

I need to automate some forms by embedding them in to for loops, however I am having problems with the input box default value.

 

Original code:

<?php echo _PICTURES;?><input class="inputbox" type="text" name="image1desc" size="10" value="
<?php echo $row->image1desc;?>" />

 

Looped code:

<?php  for ($picnumber=1; $picnumber<=2;$picnumber++){ ?>
<?php echo _PICTURES;?><input class="inputbox" type="text" name="<?php echo "image".$picnumber."desc"?>"
         size="10" value="<?php echo '$row->'.'image'.$picnumber.'desc';?>" />
<?php } ?>

Original code was getting input box's value using $row->image1desc where my code displays "$row->image1desc" in the input box. How do I fix it? The whyole idea of is to read image1desc, image2desc, image10desc, etc...

 

Thank you

Link to comment
https://forums.phpfreaks.com/topic/118841-displaying-row-name-in-a-for-loop/
Share on other sites

something like this? (not tested)

<?php  for ($picnumber=1; $picnumber<=2;$picnumber++){
$data = $row->image.$picnumber.desc;?>
<?php echo _PICTURES;?><input class="inputbox" type="text" name="<?php echo "image".$picnumber."desc"?>"
         size="10" value="image<?php echo $data;?>desc" />
<?php } ?>

just another try:

<?php  for ($picnumber=1; $picnumber<=2;$picnumber++){
$cur_data = "image".$picnumber."desc";
$data = $row->$cur_data;?>
<?php echo _PICTURES;?><input class="inputbox" type="text" name="<?php echo $cur_data;?>"
         size="10" value="<?php echo $data;?>" />
<?php } ?>

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.