[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 364
  • Last Modified:

phpflickr/lightbox2 integration issue

I'm trying to implement a flicker gallery into a website and I am successful.  However, it streams down the page in a single column.  So I am trying to write code to display 3 per row until the pictures run out.  I used print_r() to display the content of the array phpflicker provides.  The contents of it are as follows.


Array (
 [photoset] => 
Array ([id] => 72157626566656695 [primary] => 5707707046 [owner] => 62546720@N02 [ownername] => InlineOne [photo] => 
Array ( 
[0] =>Array ( [id] => 5707707046 [secret] => 7c3ffb8c18 [server] => 2615 [farm] => 3 [title] => bouncing1 [isprimary] => 1 )
 [1] =>Array ( [id] => 5707707000 [secret] => e7e0465a1f [server] => 2078 [farm] => 3 [title] => bouncing2 [isprimary] => 0 )
 [2] =>Array ( [id] => 5707706962 [secret] => ed3753522e [server] => 2500 [farm] => 3 [title] => bouncing6 [isprimary] => 0 )
 ) [page] => 1 [per_page] => 500 [perpage] => 500 [pages] => 1 [total] => 11 ) [stat] => ok )

Open in new window


Now, my currently working code is as follows:
<table width="100%" border="0" cellspacing="3" cellpadding="3"> 
                 <?php $photos = $f->photosets_getPhotos('72157626566656695'); ?>
				<?php $index = sizeof($photos); 
				$currentstart = 1;
				$currentend = 3;
				$current = 0;
				while ($index > 0)
				{?>	
					<tr>
                    	<?php for($i=0; $i<$currentend; $i++)
						{?>	
                        	<td width="34%" bgcolor="#E6E6E6">
<img src="<?php $f->buildPhotoURL($photos[photoset][photo][$current][title], 'thumbnail') ?> "alt=" <?php $photos[photoset][photo][0][title]?>" title=" <?php $photos[photoset][photo][0][title] ?> "/>
                    			<?php $current++; ?>
                        	</td>
                        <?php }?>
                 	</tr>
                    <tr>
                    	<td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                   	</tr>
      				<?php
					$index = $index - 3;
					$currentend = $currentend + 3;
					$currentstart = $currentstart +3;
    			}?>
				</table>

Open in new window


the line of code I believe would be correct to output a single picture would be:
<img src="<?php $f->buildPhotoURL($photos[photoset][photo][0], 'thumbnail') ?> "alt=" <?php $photos[photoset][photo][0] ?>" title=" <?php $photos[photoset][photo][0] ?> "/>

Open in new window


This code along with many other variations I have tried failed to work.  My question is if anyone can help me with which part of the array the line  $f->buildPhotoURL(  ,'thumbnail) requires to output the image, or to let me know if I am going about this completely wrong.



0
andrewaiello
Asked:
andrewaiello
  • 3
  • 3
1 Solution
 
magadesign_sviluppoCommented:
hi,
the code seams not working try instead:
<table width="100%" border="0" cellspacing="3" cellpadding="3"> 
                 <?php $photos = $f->photosets_getPhotos('72157626566656695'); ?>
				<?php $index = sizeof($photos); 
				$cellCount = 0;
				$cellPerRow = 3;
				 for($i=0; $i<$index ; $i++) // loop for all photos
				{
                                   if($cellCount==0){echo("<tr>")} //start row if is the first cell
                                    ?>	
					<td width="34%" bgcolor="#E6E6E6">
<img src="<?php $f->buildPhotoURL($photos[photoset][photo][$i][title], 'thumbnail') ?> "alt=" <?php $photos[photoset][photo][$i][title]?>" title=" <?php $photos[photoset][photo][$i][title] ?> "/>
                        	</td>
                        <?php
                             $cellCount++;
                              if($cellCount==$cellPerRow){echo("</tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>"); $cellCount = 0; } //end row and set cellCount to 0  if is the third cell
                               }?>
				</table>

Open in new window

hope will help
0
 
magadesign_sviluppoCommented:
sorry :)
befor closing the <table> should add more code to verify if last row wos complete
the ending would be:
 <?php
                             $cellCount++;
                              if($cellCount==$cellPerRow){echo("</tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>"); $cellCount = 0; } //end row and set cellCount to 0  if is the third cell
                               }
if($cellCount<$cellPerRow) // if row is not complete
{
for($i=$cellCount; $i<=$cellPerRow; $i++)
{
echo("<td>&nbsp;</td>"); //add missing cells
}
echo("</tr>"); // than close the row
}
?>
				</table>

Open in new window

0
 
andrewaielloAuthor Commented:
That didn't work, The issue I am having is not the formatting of the images to 3 per row, I'm getting broken image links in the correct format that I want.  But, for some reason It isn't getting the correct link to the images.  In my first post, by working I mean the format was working, not the images(I should have specified).  In the code that prints out the images, just not the right format it goes like this:
<?php $photos = $f->photosets_getPhotos('xxxxxxxxxxxxxxxxx'); ?>
<?php foreach ($photos['photoset']['photo'] as $photo): ?>
<div class="photos">
<a rel="lightbox[]" href="<?= $f->
    buildPhotoURL($photo, 'medium') ?>"
    title="<?= $photo['title'] ?>">
<img src="<?= $f->buildPhotoURL($photo, 'square') ?>"
    alt="<?= $photo['title'] ?>" title="<?= $photo['title'] ?>" />
</a>
</div>
<?php endforeach; ?>

Open in new window


with correct header includes as provided by http://www.adambate.com/how-to-add-a-flickr-based-photo-gallery-to-your-website-phpflickr-lightbox/

I was suggested to go the route of a while loop because I was told it was easier by a coworker.  
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
nplibCommented:
I don't know about you but when I do arrays like this

$photos[photoset][photo][$current][title]

I get errors, try this.

$photos['photoset']['photo'][$current]['title']

for all your array keys.
0
 
andrewaielloAuthor Commented:
I don't think I have gotten errors when not using the single quotes but I am still very new to php so I havn't done much work with arrays directly.  But I will use them from now on to ensure I don't have problems in the future.  However, I'm still getting broken image links.  I tested the two locations most likely to be correct:
$photos['photoset']['photo']['0']['title']

Open in new window

and
$photos['photoset']['photo']['0']

Open in new window


I thought maybe an echo was needed for the three references to the array in the line:
<img src="<?php $f->buildPhotoURL($photos['photoset']['photo']['0']['title'], 'thumbnail') ?> "alt=" <?php $photos['photoset']['photo']['0']['title']; ?>" title=" <?php $photos['photoset']['photo']['0']['title']; ?> "/>

Open in new window

 

but it changes nothing and gives an error for the $f->buildPhotoURL portion.

For simplicity purposes I am trying to just hard code a single image to the page with the code just above.
 
0
 
magadesign_sviluppoCommented:
if I understood well the code
<?php $photos = $f->photosets_getPhotos('xxxxxxxxxxxxxxxxx'); ?>
<?php foreach ($photos['photoset']['photo'] as $photo): ?>
<div class="photos">
<a rel="lightbox[]" href="<?= $f->
    buildPhotoURL($photo, 'medium') ?>"
    title="<?= $photo['title'] ?>">
<img src="<?= $f->buildPhotoURL($photo, 'square') ?>"
    alt="<?= $photo['title'] ?>" title="<?= $photo['title'] ?>" />
</a>
</div>
<?php endforeach; ?>

Open in new window

works well, and you need to format this code to a table with 3 cells in a row?

if so:
<?php $photos = $f->photosets_getPhotos('xxxxxxxxxxxxxxxxx'); ?>
<?php 
$cellCount = 0;
$cellPerRow = 3;
?>
<table>
<?php foreach ($photos['photoset']['photo'] as $photo): ?>
<?php if($cellCount==0){echo("<tr>")}?>
<td>
<a rel="lightbox[]" href="<?= $f->
    buildPhotoURL($photo, 'medium') ?>"
    title="<?= $photo['title'] ?>">
<img src="<?= $f->buildPhotoURL($photo, 'square') ?>"
    alt="<?= $photo['title'] ?>" title="<?= $photo['title'] ?>" />
</a>
</td>
<?php
$cellCount ++;
if($cellCount==$cellPerRow){echo("</tr><tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>"); $cellCount = 0; }
?>
<?php endforeach; ?>
<?php
if($cellCount<$cellPerRow)
{
for($i=$cellCount; $i<=$cellPerRow; $i++)
{
echo("<td>&nbsp;</td>"); 
}
echo("</tr>"); 
}
?>
</table>

Open in new window

should work,

sorry but a can't test it cuz
i don't know what are:
<?php $photos = $f->photosets_getPhotos('xxxxxxxxxxxxxxxxx'); ?>
and
"<?= $f->buildPhotoURL($photo, 'square') ?>
doing
0
 
andrewaielloAuthor Commented:
Thank you very much, this helped out so much.  After seeing your code and after looking at what is different in mine I realized I was missing the surrounding <a> </a> tags for the lightbox code in what I had.

Thanks, Dan
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now