phantomlimb Posted September 19, 2009 Share Posted September 19, 2009 I'm doing some work with PHP, and Flickr. I have an array of photos. The photos are contained in divs. I want to give the div an ID based on the result number. I don't really know where to start with this piece, hoping to get some advice from the more experienced coders amongst us. I assume i will have to count the number of the results in the array and dynamically assign the div id a number eg. the first result <div id="panel1">, the second result <div id ="panel2">. here is the piece of code i am working with, any help appreciated: <? foreach ((array)$photos_norway['photo'] as $phototagged) : ?> <div id="panel1"> <img src="<?= $f->buildPhotoURL($phototagged, 'medium') ?>" /> </div> <?php endforeach; ?> Link to comment https://forums.phpfreaks.com/topic/174787-php-foreach-array-counting-and-assigning-id-to-each-row/ Share on other sites More sharing options...
Mark Baker Posted September 19, 2009 Share Posted September 19, 2009 foreach ($photos_norway['photo'] as $id => $phototagged) { ?><div id="panel<?php echo $id; ?>"> <img src="<?php echo $f->buildPhotoURL($phototagged, 'medium'); ?>" /> </div><?php } ?> Link to comment https://forums.phpfreaks.com/topic/174787-php-foreach-array-counting-and-assigning-id-to-each-row/#findComment-921124 Share on other sites More sharing options...
phantomlimb Posted September 19, 2009 Author Share Posted September 19, 2009 Perfect, thank you very much. Link to comment https://forums.phpfreaks.com/topic/174787-php-foreach-array-counting-and-assigning-id-to-each-row/#findComment-921127 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.