PDA

View Full Version : Lightbox and PHP


troyd
01-05-2010, 12:22 PM
Has anyone tried to include the Lightbox2 using the Prototype framework to display images in a repeating region?

What I have here is a repeating table of records created with DataAssist. That all works fine. There are 3 images within each record. Right now if you click on an image thumbnail it pops up a detailed large version of the image. But then you have to close that window and click on each of the other two thumbnails one at a time to see them.

My customer wants the lightbox instead so that he can click next to see all three images in that record.

With Lightbox2 there is the rel="lightbox[group]" that allows you to show only groups with a particular name. But I can not figure out how to create this dynamically. And since the thumbnails are each in their own column of the database table, it shows the first image of each record when you click on imagethumb1.

My current code that pops up the lightbox, but shows the image1 of all records is this;

<a href="images/<?php echo $row_rsAvailable['image1']; ?>"
rel="lightbox[group]" title="<?php echo $row_rsAvailable['number']; ?>">
<img src="images/<?php echo $row_rsAvailable['image1']; ?>"
alt="Available" width="150" /></a>


So I somehow need to first echo all images in that record (image1, image2, image3). Then I need to pass the group name in the form of the id of that record. Any thoughts on doing this?

Thanks,
TroyD

SOJO web
01-08-2010, 10:12 PM
Hey Troy,

First, you are right on with the repeat region, but you need to alter the name of the group based on sets of threes... so a little modulo operation will be needed along with a system to increment for each group.



<!-- First set the group increment number -->

<?php $groupincrement = 1; ?>

<!-- Now set the row increment number (after every third row will later increase the group increment number by 1) -->

<?php $rowincrement = 1; ?>

<!-- Now, begin the loop -->

<?php do { ?>


<a href="images/<?php echo $imagename; ?>" rel="lightbox[group<?php echo $groupincrement; ?>]"><?php echo $row_image['imagename']; ?></a>

<!-- We will now increase the row increment -->
<?php ++$rowincrement; ?>

<!-- We will now test the row to see if it is the third item and if it is, we will add an increment to the group -->

<?php if ($rowincrement % 3 == 0) {
++$groupincrement;
}
?>

<?php } while condition met ?>





Best regards,

Brian

troyd
01-09-2010, 10:21 PM
As always Brian, you gave a great and detailed response. THANKS!

I will give it a try and report back.

Thanks again,
TroyD