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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

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

Post 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>
Last edited by Chris Corbyn on Thu Feb 10, 2005 9:25 am, edited 1 time in total.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

I'm going home now.... I need a day off ;-) LOL :lol:
Post Reply