www.webdeveloper.com
Results 1 to 6 of 6

Thread: PHP Gallery

Hybrid View

  1. #1
    Join Date
    Aug 2007
    Posts
    20

    PHP Gallery

    Hello,

    I am a bit stuck on how to produce this.

    What I am needing to create is a script were the admin user uploads an image from the backend.

    The image path and name that is given will be sent to the Gallery Table in the database - imageName and imagePath from this a thumbnail will have to be automatically created and then displayed via the front end.

    I am using a lightbox type feature hence why I am so confused on how to code this.

    I have been trying to get this to work but then I clicked that I have a seprate thumbnail

    I am only working on the front-end code at the momment, so far I have:

    A Gallery Manager which will house the SQL query for the class.gallery.php

    PHP Code:

    class GalleryManager{
        
        public function 
    getAllImages(){
            
            global 
    $database;
            
            
    $Query 'SELECT id, imageName, imagePath FROM Gallery';
            
            
    $rsResult $database->query($Query);
            
            
    $aGallery = array();
            
            while(
    $aImage $database->fetch_array($rsResult)){
                
                
    $aGallery[$aImage['id']] = $aImage['imagePath'];
                
            }
            return 
    $aGallery;
        
            }
        } 
    class.gallery.php - The Working End

    PHP Code:

    define
    ('IMG_PATH''includes/images/Gallery/');

    include(
    'class.galleryManager.php');

    class 
    Gallery{

        private 
    $imgRoot IMG_PATH;
        
        public function 
    getGalleryImages(){
            
            
    $galleryManager = new GalleryManager();
            
            
    $aGetPages $pageManager->getAllImages();
            
            
    $sOutput .= ''."\n";
            
            
    $sOutput .= '<div id="gallery-images">'."\n";
            
            foreach(
    $aGetPages as $key => $value){
                
                
    $sOutput .='<a href="'.$this->imgRoot.$aImage['imagePath'].'" class="zoomBox" title="'.$aImage['imageName'].'"><img src="'.$this->imgRoot.$aImage['imagePath'].'" alt="Image" /></a>'."\n";

            }

            
    $sOutput .="</div>"."\n";        
        }
        

    Index.php - How The 2 Documents Come Togeather

    The Navigation Works Fine

    PHP Code:

    <?php

    include('includes/header.php');

    include(
    'includes/class/class.gallery.php');

    $newNavigation = new Navigation();

    $newGallery = new Gallery();

    ?>

        <?php echo $newNavigation->mainMenu();?>

        <h1  class="Heading">View Our Work</h1>
        
        <?php echo $newGallery->getGalleryImages();?>


    <?php include('includes/footer.php');     ?>

  2. #2
    Join Date
    Feb 2005
    Location
    Tauranga
    Posts
    2,062
    I see a possible issue;

    your function GalleryManager::getAllImages(); has all mis-matched variable names.
    Last edited by Sheldon; 12-08-2010 at 05:00 PM.

  3. #3
    Join Date
    Feb 2005
    Location
    Tauranga
    Posts
    2,062
    PHP Code:
    <?php
        define
    ('IMG_PATH''includes/images/Gallery/');

        include(
    'class.galleryManager.php');

        class 
    Gallery{

            private 
    $imgRoot IMG_PATH;
        
            public function 
    getGalleryImages(){
            
                
    $galleryManager = new GalleryManager();
            
                
    $images $galleryManager->getAllImages();
            
                
    $sOutput '<div id="gallery-images">'."\n";
            
                foreach(
    $images as $key => $image){
                
                    
    $sOutput .='<a href="'.$this->imgRoot.$image['imagePath'].'" class="zoomBox" title="'.$image['imageName'].'"><img src="'.$this->imgRoot.$image['imagePath'].'" alt="Image" /></a>'."\n";

                }

                
    $sOutput .="</div>"."\n";
        
                return 
    $sOutput;
            }
        
        }
    Last edited by Sheldon; 12-08-2010 at 04:59 PM.

  4. #4
    Join Date
    Aug 2007
    Posts
    20
    Thanks,

    That works ok but it is only showing the first letter of the file name is this because I have not included the file type anywhere. I have manually imported the file name into the db but I am having no luck

  5. #5
    Join Date
    Aug 2007
    Posts
    20
    Quote Originally Posted by jzm View Post
    Thanks,

    That works ok but it is only showing the first letter of the file name is this because I have not included the file type anywhere. I have manually imported the file name into the db but I am having no luck
    Images:

    The above code now produces:

    Main View

    http://dev.noo.co.nz/Nyken/Gallery_I...alleryMain.png

    Code Snippit

    http://dev.noo.co.nz/Nyken/Gallery_I...alleryCode.png

    Database View

    http://dev.noo.co.nz/Nyken/Gallery_I...ryDatabase.png

    How could I fix this?

  6. #6
    Join Date
    Feb 2005
    Location
    Tauranga
    Posts
    2,062
    Your issue is here;

    In your GalleryManager Class you are creating an array based on the Database ID, and image path

    $aGallery[$aImage['id']] = $aImage['imagePath'];

    In your Gallery Class you are looping that array, and then trying to access the 'imagePath' of the array which does not exists. Hence why it is giving the first letter in the filename.


    sOutput .='<a href="'.$this->imgRoot.$image['imagePath'].'" class="zoomBox" title="'.$image['imageName'].'"><img src="'.$this->imgRoot.$image['imagePath'].'" alt="Image" /></a>'."\n";

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles