Solved

PHP snippet change not working

Posted on 2011-03-03
4
232 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

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

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

680 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