Keeping loop setting

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
lunartek
Forum Newbie
Posts: 15
Joined: Thu Apr 24, 2003 1:10 pm

Keeping loop setting

Post by lunartek »

I have a minor problem in a script which should display 6 images per page, 3 per row. All works except it don't keep the 3 images per row setting on next page.

I can't figure out what i'm missing, must be something simple (always is!).
My guess is that I need to use a loop instead of if ($i==3){ echo "<BR>"; } but can't figure out quite how.

Anyway, here's a sample from my script...

Code: Select all

<?
global $show;
$dir = opendir("$DOCUMENT_ROOT"."/$dirname");
$i=1;
$count=0;
$increment = $rows*$cols-1;

$begin = (!empty($_GET['show']) && is_numeric($_GET['show']) && $_GET['show'] > 0) ? $_GET['show'] : 1;
$end = $begin + $increment;

while ($filename = readdir($dir)) {
if (ereg ("(.*)\.gif", $filename)) {
if ($i >= $begin && $i <= $end) {

if ($count >= 0) {
echo "<img src="http://$SERVER_NAME/$dirname/$filename"> ";
}
if ($i==3){ echo "<BR>"; }
}

$i++;
$count++;
}
}
closedir($dir);


if ($begin!=1){
echo "<BR><a href="test2.php?show=".($begin-$increment-1)."">previous images</a>";
}
if ($end<=$count){
echo "<BR><a href="test2.php?show=".($begin+$increment+1)."">next images</a>";
}
>?

Any help would be appreciated :)
--lunartek
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

maybe you should reset $i after <br /> is printed.
Or use ($i%3)==0 as condition.
lunartek
Forum Newbie
Posts: 15
Joined: Thu Apr 24, 2003 1:10 pm

Post by lunartek »

volka,
Thanks for your great help.
It works fine now, ($i%3)==0 did it :)
Post Reply