Page 1 of 1

[SOLVED] My for() loop won't iterate

Posted: Thu Feb 10, 2005 5:26 am
by Chris Corbyn
It's probably really obvious if you're looking at this from your eyes not mine but I've been looking at it for ages and I still can't see what's wrong. The first for() loop is just doing one repitition and then stopping. $gall_rows is 2 (I've checked this) and I've tried just using predefined numbers ( for($i=0; $i<2; $i++) ) in the loopp but still only get one reptition. Can anybody spot the reason?

Thanks :-)

Code: Select all

<table width="70%" align="center" cellpadding="0" cellspacing="0" border="0">
<?php

$gall_array = array();
$g = 0; //Counter for num folders
$handle = opendir('gallery'); //Where pics are stored
while ($file = readdir($handle)) &#123;
	if (is_dir('gallery/'.$file) && $file != '..' && $file != '.') &#123;
		$gall_array&#1111;$g] = $file; //Keep a record of the folders
		$g++; //Count gallery folders
	&#125;
&#125;

$gallerycount = $g;

//Using a table with 3 cells per row
$gall_rows = ceil($gallerycount/3);
$count = 0;
for ($i=0; $i<$gall_rows; $i++) &#123; //This only does one loop
	echo "\t".'<tr>'."\r\n";
		for ($i = $count; $i < ($count+3); $i++) &#123;
			if ($i < count($gall_array)) &#123;
				echo "\t\t".'<td>'."\r\n";
				echo "\t\t\t".'<table cellspacing="0" cellpadding="0" border="0" class="norm" style="float:

left">'."\r\n";
				echo "\t\t\t\t".'<tr>'."\r\n";
				echo "\t\t\t\t\t".'<td width="170" height="170" align="center" valign="middle" background="

img/frame.gif"><img src="gallery/'.$gall_array&#1111;$i].'/thumb.jpg"></td>'."\r\n";
				echo "\t\t\t\t".'</tr>'."\r\n";
				echo "\t\t\t\t".'<tr>'."\r\n";
				echo "\t\t\t\t\t".'<td><b>'.$gall_array&#1111;$i].'</td>'."\r\n";
				echo "\t\t\t\t".'</tr>'."\r\n";
				echo "\t\t\t".'</table>'."\r\n";
				echo "\t\t".'</td>'."\r\n";
			&#125; else &#123;
				echo "\t\t".'<td>'."\r\n";
				echo "\t\t\t".'<table cellspacing="0" cellpadding="0" border="0" class="norm" style="float:

left">'."\r\n";
				echo "\t\t\t\t".'<tr>'."\r\n";
				echo "\t\t\t\t\t".'<td width="170" height="170" align="center" valign="middle">&nbsp;</td>'

."\r\n";
				echo "\t\t\t\t".'</tr>'."\r\n";
				echo "\t\t\t\t".'<tr>'."\r\n";
				echo "\t\t\t\t\t".'<td>&nbsp;</td>'."\r\n";
				echo "\t\t\t\t".'</tr>'."\r\n";
				echo "\t\t\t".'</table>'."\r\n";
				echo "\t\t".'</td>'."\r\n";
			&#125;
		&#125;
		//$count += 3;
		echo "\t".'</tr>'."\r\n";
&#125;

?>
</table>

Posted: Thu Feb 10, 2005 5:40 am
by JayBird
it is becuase you have two for loops, both using $i as the increment value, so when the second for loop ends, the first one wont execute again because the values is greater than 2

Posted: Thu Feb 10, 2005 5:50 am
by Chris Corbyn
I'm going home now.... I need a day off ;-) LOL :lol: