Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 136,581 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,934 people online right now. Registration is fast and FREE... Join Now!




photo gallary

2 Pages V  1 2 >  
Reply to this topicStart new topic

photo gallary

Rating  5
dreamincodehamza
5 Oct, 2008 - 11:38 PM
Post #1

D.I.C Head
Group Icon

Joined: 12 Sep, 2008
Posts: 110


Dream Kudos: 75
My Contributions
Please check this photo gallary which i have created by myself
with paging.

Actually what is happening in it is
i am getting images from directory by giving path .

and there is few errors in it if you run it and increate the
number of images per page then few images will not
show in few rows please check it and tell me
how would i improve it .
CODE

<?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 ::&nbsp; '.$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]; ?>&nbsp;</td>
                                      <?php $j++; ?>
                                      <td align="center"><?php echo $imgsNames[$j]; ?>&nbsp;</td>
                                     <?php  $j++; ?>
                                      <td align="center"><?php echo $imgsNames[$j]; ?>&nbsp;</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]; ?>&nbsp;</td>
                                          <?php $j++; ?>
                                          <td align="center"><?php echo $imgsNames[$j]; ?>&nbsp;</td>
                                         <?php  $j++; ?>
                                          <td align="center"><?php echo $imgsNames[$j]; ?>&nbsp;</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]; ?>&nbsp;</td>
                              <?php $j++; ?>
                              <td align="center"><?php echo $imgsNames[$j]; ?>&nbsp;</td>
                             <?php  $j++; ?>
                              <td align="center"><?php echo $imgsNames[$j]; ?>&nbsp;</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;
?>
<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>
</body>
</html>



User is offlineProfile CardPM
+Quote Post

pemcconnell
RE: Photo Gallary
6 Oct, 2008 - 12:53 AM
Post #2

D.I.C Regular
Group Icon

Joined: 5 Aug, 2008
Posts: 396



Thanked: 37 times
Dream Kudos: 75
My Contributions
I don' t have time to go through your code just yet (will do later), but the content generated by the PHP is outputted before the <body> tag.
User is offlineProfile CardPM
+Quote Post

dreamincodehamza
RE: Photo Gallary
7 Oct, 2008 - 10:53 AM
Post #3

D.I.C Head
Group Icon

Joined: 12 Sep, 2008
Posts: 110


Dream Kudos: 75
My Contributions
SO what wrong if it is generating before what should i do .
and
please check it i am waiting for your reply
User is offlineProfile CardPM
+Quote Post

engale
RE: Photo Gallary
7 Oct, 2008 - 11:26 AM
Post #4

D.I.C Addict
Group Icon

Joined: 30 Sep, 2008
Posts: 549



Thanked: 2 times
Dream Kudos: 50
My Contributions
simply move...

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>


before your <?php line. That will put the body of your page inside the body of the html codes
User is offlineProfile CardPM
+Quote Post

dreamincodehamza
RE: Photo Gallary
8 Oct, 2008 - 09:40 PM
Post #5

D.I.C Head
Group Icon

Joined: 12 Sep, 2008
Posts: 110


Dream Kudos: 75
My Contributions
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 ::&nbsp; '.$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]; ?>&nbsp;</td>
                                      <?php $j++; ?>
                                      <td align="center"><?php echo $imgsNames[$j]; ?>&nbsp;</td>
                                     <?php  $j++; ?>
                                      <td align="center"><?php echo $imgsNames[$j]; ?>&nbsp;</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]; ?>&nbsp;</td>
                                          <?php $j++; ?>
                                          <td align="center"><?php echo $imgsNames[$j]; ?>&nbsp;</td>
                                         <?php  $j++; ?>
                                          <td align="center"><?php echo $imgsNames[$j]; ?>&nbsp;</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]; ?>&nbsp;</td>
                              <?php $j++; ?>
                              <td align="center"><?php echo $imgsNames[$j]; ?>&nbsp;</td>
                             <?php  $j++; ?>
                              <td align="center"><?php echo $imgsNames[$j]; ?>&nbsp;</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>

User is offlineProfile CardPM
+Quote Post

ap0c0lyps3
RE: Photo Gallary
9 Oct, 2008 - 09:21 AM
Post #6

D.I.C Head
Group Icon

Joined: 19 Jun, 2007
Posts: 79


Dream Kudos: 25
My Contributions
Why don't you have a look at Lightbox its a "prettier" way of displaying your image.

This post has been edited by ap0c0lyps3: 9 Oct, 2008 - 09:22 AM
User is offlineProfile CardPM
+Quote Post

dreamincodehamza
RE: Photo Gallary
9 Oct, 2008 - 12:03 PM
Post #7

D.I.C Head
Group Icon

Joined: 12 Sep, 2008
Posts: 110


Dream Kudos: 75
My Contributions
ap0c0lyps3 i appriciate this link but if you check my code then i think its better make me understand.

User is offlineProfile CardPM
+Quote Post

dreamincodehamza
RE: Photo Gallary
17 Oct, 2008 - 11:47 AM
Post #8

D.I.C Head
Group Icon

Joined: 12 Sep, 2008
Posts: 110


Dream Kudos: 75
My Contributions
Anyone check my photogallary.
All photogallary source code is about in posts
Please execute my code and increase the number of
images to view on page and you will see an error in
5 or 6 six row please tell me why this is happening .
And

- 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

User is offlineProfile CardPM