Pagination of images - varying number of images depending on orientation

Discussion in 'PHP' started by chuckylefrek, Dec 6, 2007.

  1. #1
    I have read alot of messages about basic pagination. However none appear to deal with the issue where the number of items to be displayed on each page varies. In my case, I am creating a thumbnail gallery of product images. The images are either landscape or portrait, and the page may conntain a mixture of the two. Therefore depending on the orientation of the images, the total amount of images that can be displayed on the page will vary.

    I would appreciate advice on how best to implement pagination for this scenario.

    Here is the page that currently does not have any pagination

    http://www.trullcornershop.co.uk/inside2.php

    Many thanks
    Paul
     
    chuckylefrek, Dec 6, 2007 IP
  2. Gawk

    Gawk Peon

    Messages:
    427
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Paul, are you pulling the images from a directory or a database?
     
    Gawk, Dec 6, 2007 IP
  3. chuckylefrek

    chuckylefrek Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi there

    The details of all the images are stored in a database. I don't actually store the image itself in the database - just the path.

    Thanks

    Paul
     
    chuckylefrek, Dec 6, 2007 IP
  4. Gawk

    Gawk Peon

    Messages:
    427
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #4
    OK, when you store the image path in the database you could also store the image dimensions as well. Using the image width info (i noticed your images are all the same height) you can work out if 'x' amount of images will fit on the row, if not start the next row.

    Call enough of the images to fit the page, which will probably be either 9 or 12, then loop through them working out if they fit on the row, when you have filled three rows you may have some images not shown from the result set. In that case count how many were not shown and adjust your next database call to start that number of lines back.

    If you can't store the image dimensions in the database you can always get them using getimagesize();

    Hope this helps - and you understand my ramblings!
     
    Gawk, Dec 6, 2007 IP
  5. chuckylefrek

    chuckylefrek Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks gawk - I really appreciate the help!

    What you suggests sounds like a great solution - there should be no problem storing the images in the database as I resize all the uploaded images anyway.

    I will give your solution a try!

    Many thanks

    Paul
     
    chuckylefrek, Dec 6, 2007 IP