Solved

PHP snippet change not working

Posted on 2011-03-03
4
227 Views
Last Modified: 2012-06-21
I am using the following PHP snippet to loop through a directory of images and display thumbnails.  The script is currently hard-coded to display up to 10 images.  I am changing the value where you see 10 to increase to 20 photos.  I figured this was a simple change, but even when I change all instances of 10 to 20 it STILL only shows 10 images?  What am I missing here?

									<?
									$image = "<br>";
									$img_cnt = 1;
									$image .= "<a href=/feeds/sancap/rets_images/$MLNumber.jpg rel=\"enlargeimage\" rev=\"targetdiv:loadarea\"><img src=/feeds/sancap/rets_images/$MLNumber.jpg alt='' width='100' height='75' border='0' /></a>&nbsp;";
									for ($c=1;$c<10;$c++) {
										if ($c<10)
											$c_ext = "0".$c;
										else
											$c_ext = $c;

										if (file_get_contents("http://www.mydomain.com/feeds/sancap/rets_images/{$MLNumber}_{$c_ext}.jpg"))
											$image .= "<a href=/feeds/sancap/rets_images/{$MLNumber}_{$c_ext}.jpg rel=\"enlargeimage\" rev=\"targetdiv:loadarea\"><img src=/feeds/sancap/rets_images/{$MLNumber}_{$c_ext}.jpg alt='' width='100' height='75' border='0' /></a>&nbsp;";
										else
											$c=12;

										$img_cnt++;
										if ($img_cnt == 5) {
											$image .= "<br>";
											$img_cnt = 0;
										}

									}

									?>   

Open in new window

0
Comment
Question by:pda4me
  • 2
4 Comments
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 35029054
This script, as it stands, will bomb out if it fails to find one image in the sequence so if you have missed named an image that could stop the script working.
0
 
LVL 34

Accepted Solution

by:
Beverley Portlock earned 250 total points
ID: 35029096
Also this line

else
     $c=12;

looks like it is meant to force a loop exit. It would be better to make this independent of the number of loop iterations by using break instead. Change it like so

else
     break;



0
 
LVL 4

Assisted Solution

by:Tomun
Tomun earned 250 total points
ID: 35036799
You only need to change the FIRST instance of 10 in the 'for' statement.

 if you changed the 'if' statement too it would have failed to find images numbered 10 or higher.

Do make bportlock's suggested change and use break.
0
 

Author Closing Comment

by:pda4me
ID: 35182673
Thanks!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Creating Image Thumbnails Using PHP 3 15
writting html or javascript in PHP 8 13
using hash in login 34 13
PHP JSON Clean up 5 0
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now