Hello. i have this code bellow that is supposed to list av images in a folder wich is do, and then list them with 5 per row but the counter is not working and it's a long line of links insteed of 5 per row as it is supposed to be, why is this? i hope someone can help. <? $files = glob('*.jpg'); rsort($files); $max=5; $i=1; foreach($files as $file){ echo '<A HREF="pop.php?file=' . $file . '" onClick="return popup(this)">' . $file . '</A>'; if($i==$max) echo '<br>'; $i=0; $i++; } ?> PHP:
Putting things on the same line doesn't have any magic effect. What's happening here is that the "echo" only happens if the "if" is satisfied, but "$i=0" always happens either way. Change it to this: if($i==$max) { echo '<br>'; $i=0; } Code (markup): The curly braces tell it to group both of those together as the consequence of the "if".
thank you very much! also i have one more question about the code. the images are named 1.jpg, 2.jpg and so on all the way up to 4000+ how can i make the sort function sort the images from 1 to 4000 and so on? currently it's mixing the up and are in no order at all :/