Newbie: foreach
Posted: Thu Jul 30, 2009 4:13 pm
I am (trying) to create an online gallery. I have a div to show the thumbnails, and a div to show the main image when you click the thumbnail (I guess like a banner rotator).
Main Image Div:
Thumbnail Div:
In I have:-
It shows the 4 latest thumbnails in the thumbnail Div. When you click on a thumbnail, the main image appears in the main image Div:
It works fine except when you initially load the page, no main image shows UNTIL you select a thumbnail. I tried adding this to the main DIV...
It works, but obviously shows 4 main images. How can I change to only show 1 image just on this occasion? If I change to =1 then I will only get 1 thumbnail.
I am not a programmer, I am using bits and bobs of code from several sources so go easy on me.
But I am trying to learn.
Main Image Div:
Code: Select all
<div class="main_image"><img src="<?php echo $p['image']; ?>"/></div>Code: Select all
<?php foreach( $posts as $p ) { ?>
<div class="post">
<?php if( $p['image'] ) { ?>
<a href="<?php echo $p['image']; ?>">
<img src="<?php echo $p['thumb']; ?>"/></a>
</div>
<?php } else { ?>Code: Select all
config.class.phpCode: Select all
public static $postsPerPage = 4;It works fine except when you initially load the page, no main image shows UNTIL you select a thumbnail. I tried adding this to the main DIV...
Code: Select all
<?php foreach( $posts as $p ) { ?>
<div class="main_image"><img src="<?php echo $p['image']; ?>"/></div>
<?php } else { ?>Code: Select all
<?php foreach( $posts as $p ) { ?>Code: Select all
public static $postsPerPage = 4;I am not a programmer, I am using bits and bobs of code from several sources so go easy on me.