omen Posted August 8, 2008 Share Posted August 8, 2008 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 More sharing options...
jonsjava Posted August 8, 2008 Share Posted August 8, 2008 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 } ?> Link to comment https://forums.phpfreaks.com/topic/118841-displaying-row-name-in-a-for-loop/#findComment-611982 Share on other sites More sharing options...
omen Posted August 8, 2008 Author Share Posted August 8, 2008 Didn't work, now it displays "image1descdesc" in the input box instead of the real data from mysql. I removed the extra "desc" and still it calculates the value of $data and puts it in in the input box. Link to comment https://forums.phpfreaks.com/topic/118841-displaying-row-name-in-a-for-loop/#findComment-611990 Share on other sites More sharing options...
jonsjava Posted August 8, 2008 Share Posted August 8, 2008 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 } ?> Link to comment https://forums.phpfreaks.com/topic/118841-displaying-row-name-in-a-for-loop/#findComment-611999 Share on other sites More sharing options...
omen Posted August 8, 2008 Author Share Posted August 8, 2008 That worked like a charm. I am wonder why it cannot be included in 1 line of code? Thank you for your help. Link to comment https://forums.phpfreaks.com/topic/118841-displaying-row-name-in-a-for-loop/#findComment-612007 Share on other sites More sharing options...
jonsjava Posted August 8, 2008 Share Posted August 8, 2008 you can, but I always like to be descriptive in my code. A little more bulky, but easier to maintain, if the need arises. Link to comment https://forums.phpfreaks.com/topic/118841-displaying-row-name-in-a-for-loop/#findComment-612016 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.