poniżej przedstawiam kod który ma wyświetlić pojedyncze zdjęcie z galerii.
$zapytanie = "SELECT id, tytul, galeriaduze, galeriamale FROM `newsy` WHERE id='$id' "; $wynik = mysql_query($zapytanie); while ( $dane = mysql_fetch_row($wynik) ) { $tytul = $dane[1]; $gd = $dane[2]; $gm = $dane[3]; class PaginateDirectory{ var $sDirectoryPath; var $iCurrentPage; var $iNumberResources; var $iNumberPerPage; var $aImages; function PaginateDirectory($path, $page){ $this->resetVars(); $this->_setPath($path); $this->_setCurrentPage($page); $this->aImages = $this->getResources($path); } # end constructor function resetVars(){ $this->sDirectoryPath = NULL; $this->iCurrentPage = 0; $this->iNumberResources = 0; $this->iNumberPerPage = NUMBER_PER_PAGE; $this->aImages = array(); return; } function _setPath($path){ $this->sDirectoryPath = $path; return; } function _setCurrentPage($page){ if( (int)$page < 1 ){ $page = 1; } $this->iCurrentPage = (int)$page; return; } function getResources($path){ $container = array(); $total = 0; if (is_dir($path)){ if ($handle = opendir($path)){ $begin = ($this->iCurrentPage > 1) ? (($this->iCurrentPage - 1) * NUMBER_PER_PAGE) : 0; $end = $begin + NUMBER_PER_PAGE - 1; while (false !== ($file = readdir($handle))){ if ($file != '.' && $file != '..' && !is_dir($path . $file)){ if( ($total > $begin) && ($total < $end) ){ $size = @getimagesize($path . $file); $container[$total] = array('file' => $file, 'dimensions' => $size[3] ); } $total++; } } } } $this->iNumberResources = $total; return $container; } function getImages(){ return $this->aImages; } function displayCount(){ $fromNumber = ($this->iCurrentPage > 1) ? (($this->iCurrentPage - 1) * NUMBER_PER_PAGE) + 1 : $this->iCurrentPage; $toNumber = $fromNumber + NUMBER_PER_PAGE - 1; if ($toNumber > $this->iNumberResources){ $toNumber = $this->iNumberResources; } return 'Zdjęcie <b>' . $fromNumber . '</b> / <b> <b>' . $this->iNumberResources . '</b>'; } function displayLinks(){ $numberPages = ceil($this->iNumberResources / NUMBER_PER_PAGE); $output = array(); $previousPage = $this->iCurrentPage - 1; $nextPage = $this->iCurrentPage + 1; if( $previousPage !== 0 ){ $output[] = '<a href="/photo.php?id='.$_GET['id'].'&page='.$previousPage.'">[<< Poprzednie]</a>'; } if ( $nextPage <= $numberPages ){ $output[] = '<a href="/photo.php?id='.$_GET['id'].'&page='.$nextPage.'">[Następne >>]</a>'; } return implode(' ', $output); } } # end class define('NUMBER_PER_PAGE', 1); define('PATH_TO_DIR', ''.$dane[2].''); $page = isset($_GET['page']) ? (int)$_GET['page'] : 1; $list = new PaginateDirectory(PATH_TO_DIR, $page); ?> <table width="100%"> <tr> </tr> <tr> <td colspan="2"> <? foreach( $list->getImages() as $index => $image ): ?> <fieldset> </fieldset> <br /> <? endforeach; ?> </td> </tr> <tr> </tr> </table> <?php } ?>
I wszystko fajnie działa, pokazuje się paginacja dolna i górna, tylko nie wyświetla się zdjęcie czyli pętla foreach.
<? foreach( $list->getImages() as $index => $image ): ?> <fieldset> </fieldset> <br /> <? endforeach; ?>
bardzo proszę o pomoc co może być nie tak że nie wykonuje się ta pętla.
PATH_TO_DIR jest ścieżką do pliku gdzie są duże zdjęcia.