What you guys saying it all about.
i wanted to know that
- is this is a correct way of making photo gallary .
- how i can improve this .
- any suggestion on it.
- any blunder or error you have seen.
and there is an error in it
when you include more then 20 images then
it show in 3 row last col not one image
any one have any idea about that.
CODE
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>photogallarywork</title>
</head>
<body>
<?php
//calculate total pages.
$totalImages = 0;
$i=0; //images names counting
$imgNumber=0; //used to show the img name in cols 1 and 2.
$imgsNames = array(); //to store the names of the images.
$ImagesStorageArray = array(); //all the images store in a array by using this array.
$dirname = 'entertainment/img'; //directory in which images are located.
$dh = opendir($dirname);
while ( ! is_bool( $file = readdir( $dh )) ) {
$dir = ( is_dir($file) ) ? $dir = 'true' : $dir = 'false';
if($dir=='true') { }else{ if( $file=='Thumbs.db'){ continue;} $ImagesStorageArray[] = $file; $totalImages++;}
}//end while
echo 'Total Images :: '.$totalImages.'<br>';
// number of images in folder.
$total_items = $totalImages;
//images perpage
$perPage = 8;
//current page number
$pageNum = ($_GET[pageNum]=='')? 1 : $_GET[pageNum]; #set default page number.
$cur = ceil( $per_page/ $pageNum) + 1; // Current page number
//start position(key) in the array
$start = ($_GET[start]=='')? 0 : $_GET[start] - $perPage;
//end position(key) in the array
$end = ($_GET[start]=='')? $perPage : $_GET[start];
echo '<table border=1>';
$startval = ($_GET[start]=='')? 0 : $start;
for( $record=$startval; $record <= $end;$record++) {
/******* SHOWING THE IMAGES IN TABLES ************/
if ( empty($firstCol) ) { //IF 'FIRST COLUMN' IS EMPTY THEN SHOW IT
//1st COL
$imgsNames[$i] = $ImagesStorageArray[$record];
?> <tr>
<td align=center>
<a href="<?php echo $dirname."/".$ImagesStorageArray[$record]; ?>" target="_blank">
<img src=<?php echo $dirname ?>/<?php echo $ImagesStorageArray[$record]?> width=100 height=100 border=0>
</a>
</td>
<?php $firstCol = 1; ?>
<?php $i++; ?>
<?php
$imgNumber++;
if( $perPage==$imgNumber) {
$k = ( $j=='' )? $j=0 : $j=$j;
for ($j=$k; $j <= $perPage;) {
?>
<tr>
<td align="center"><?php echo $imgsNames[$j]; ?> </td>
<?php $j++; ?>
<td align="center"><?php echo $imgsNames[$j]; ?> </td>
<?php $j++; ?>
<td align="center"><?php echo $imgsNames[$j]; ?> </td>
</tr>
<?php $j++;
break;
}//for end
}//if end
} else if( !empty($firstCol) && empty($secondCol) ) { //IF FIRST COLUM IS NOT EMPTY THEN SHOW ' SECOND COLUMN '
//2nd COL
//storing names in array
$imgsNames[$i] = $ImagesStorageArray[$record];?>
<td align=center>
<a href="<?php echo $dirname."/".$ImagesStorageArray[$record]; ?>" target="_blank">
<img src=<?php echo $dirname ?>/<?php echo $ImagesStorageArray[$record]?> width=100 height=100 border=0>
</a>
</td>
<?php $secondCol = "1"; ?>
<?php $i++; ?>
<?php
$imgNumber++;
//SHOWING IMAGES WHEN COUNT ENDS
if( $perPage==$imgNumber) {
$k = ( $j=='' )? $j=0 : $j=$j;
for ($j=$k; $j <= $perPage;) {
?>
<tr>
<td align="center"><?php echo $imgsNames[$j]; ?> </td>
<?php $j++; ?>
<td align="center"><?php echo $imgsNames[$j]; ?> </td>
<?php $j++; ?>
<td align="center"><?php echo $imgsNames[$j]; ?> </td>
</tr>
<?php $j++;
break;
}//for end
}//if end
?>
<?php } elseif( !empty($firstCol) && !empty($secondCol) ) {//IF BOTH COLUM ARE NOT EMPTY THEN SHOW THIRD
//3rd COL
//storing names in array
$imgsNames[$i] = $ImagesStorageArray[$record];
?> <?php $cell = 3; ?>
<td align=center>
<a href="<?php echo $dirname."/".$ImagesStorageArray[$record]; ?>" target="_blank">
<img src=<?php echo $dirname ?>/<?php echo $ImagesStorageArray[$record]?> width=100 height=100 border=0>
</a>
</td>
</tr>
<?php $i++; ?>
<?php
//MAKE EMPTY BOTH COULMN
$firstCol = '';
$secondCol = '';
?>
<?php $imgNumber++; ?>
<?php //showing images names
$k = ( $j=='' )? $j=0 : $j=$j;
for ($j=$k; $j <= $perPage;) {
?>
<tr>
<td align="center"><?php echo $imgsNames[$j]; ?> </td>
<?php $j++; ?>
<td align="center"><?php echo $imgsNames[$j]; ?> </td>
<?php $j++; ?>
<td align="center"><?php echo $imgsNames[$j]; ?> </td>
</tr>
<?php $j++; ?>
<?
break;
}//for end. ?>
<?php
}//if end
}//for end
echo '</table>';
$maxPages = ceil($total_items/$perPage);
$self = $_SERVER['PHP_SELF'];
$nav = '';
for($page = 1; $page <= $maxPages; $page++)
{
$start = ceil( $perPage * $page );
if ($page == $pageNum)
{
$nav = $nav." $page "; // no need to create a link to current page
}
else
{
$nav = $nav." <a href=\"$self?pageNum=$page&start=$start\">$page</a> ";
}
}
echo '<br>';
echo $nav;
?>
</body>
</html>