Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PHP snippet change not working

Posted on 2011-03-03
4
Medium Priority
?
235 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1000 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 1000 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

Independent Software Vendors: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
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 look for a specific file type in a local or remote server directory using PHP.

705 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