Looping Help
Posted: Mon Sep 05, 2005 10:03 pm
I have a page that is gathering all of the thumbnails in a directory and displaying them by increments of 6 or 12 (or whatever the user chooses). My loop is working and page numbering is working. But when someone clicks on a page number to view the thumbnails on that page, it seems as though my thumbnail array does not work. Here is my code:
Code: Select all
<?php
$thumbs = array();
$directory = opendir($sessionFOLDER);
while(($file = readdir($directory)) !== false) {
if($file !== '.' && $file !== '..' && !is_dir($file)) {
$thumbs[] = $file;
}
}
closedir($directory);
sort($thumbs);
// get records per page number
if (!$recPerPage) { $recPerPage = 12; }
// paging the records
if (!$numDisplay) { $numDisplay = 1; }
$totalThumbs = sizeof($thumbs);
// divide the amount of $totalThumbs by $recPerPage to determine how many pages needed<br>
$totalPages = ceil($totalThumbs/$recPerPage);
$pageCount = 1;
if (!$pageNum) { $pageNum = 1; }
// set first thumbnail on page
if ($pageNum!=1) {
$startThumb = $recPerPage*($pageNum-1);
$i = $startThumb;
} else {
$i = 0;
}
echo $i;
?>
<?php if ($totalPages>1) { // if there is more than one page show this paging table ?>
<table border="0" align="center" cellpadding="1" cellspacing="2">
<tr>
<td><h1><strong>[</strong></h1></td>
<?php while ($pageCount<=$totalPages) { ?>
<td><h1><a href="browsePhotos.php?<?php echo $_SERVER['QUERY_STRING']; ?>&pageNum=<?php echo $pageCount ?>" class="pagingLinks"><?php echo $pageCount ?></a></h1></td>
<?php $pageCount = $pageCount+1; ?>
<?php } ?>
<td><h1><strong>]</strong></h1></td>
</tr>
</table>
<?php } ?>
<hr align="center" width="90%" size="1" id="div" color="#E8E8E8">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<?php do { ?>
<?php $colNUM = 0; ?>
<tr>
<?php do { ?>
<?php $colNUM = $colNUM+1; ?>
<!-- BEGIN -->
<td align="center" valign="middle"><table border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="4"><img src="/graphics/home/box_cornertopleft.gif" width="4" height="4"></td>
<td background="/graphics/home/box_sidetop.gif"><img src="/graphics/home/box_sidetop.gif" width="5" height="4"></td>
<td height="4"><img src="/graphics/home/box_cornertopright.gif" width="4" height="4"></td>
</tr>
<tr>
<td width="4" background="/graphics/home/box_sideleft.gif"><img src="/graphics/home/box_sideleft.gif" width="4" height="4"></td>
<td><a href="#" onclick="javascript:window.open('/common/photoDetails.php?filePath=<?php echo str_replace("thumbnails","images",$sessionFOLDER)."/".$thumbs[$i]; ?>','print','width=800,height=700,scrollbars=yes,toolbar=no,status=no,menubar=no,copyhistory=no');"><img src="<?php echo $sessionFOLDER."/".$thumbs[$i]; ?>" border="0"></a></td>
<td width="4" background="/graphics/home/box_sideright.gif"><img src="/graphics/home/box_sideright.gif" width="4" height="4"></td>
</tr>
<tr>
<td height="4"><img src="/graphics/home/box_cornerbotleft.gif" width="4" height="4"></td>
<td background="/graphics/home/box_sidebot.gif"><img src="/graphics/home/box_sidebot.gif" width="3" height="4"></td>
<td height="4"><img src="/graphics/home/box_cornerbotright.gif" width="4" height="4"></td>
</tr>
</table>
</td>
<!-- END -->
<?php $i++; ?>
<?php } while ($colNUM<=5 && $i<$recPerPage); ?>
</tr>
<?php } while ($i<$recPerPage); ?>
</table>
<hr align="center" width="90%" size="1" id="div" color="#E8E8E8">
<table border="0" align="center" cellpadding="2" cellspacing="2">
<tr>
<td><h1>Paging</h1></td>
<td><h1> </h1></td>
<td><h1> </h1></td>
<td><h1> </h1></td>
<td><h1> </h1></td>
</tr>
</table>