Image Gallery with PHP

Discussion in 'PHP' started by ademmeda, May 9, 2011.

  1. #1
    Hi,

    I am coding a website with PHP and I want to add a very simple image gallery on one of its pages. I want it to be as simple as it can be. I searched for tutorials and codes and I found a few useful resources.

    I want to ask if it is possible to create an image gallery without using JavaScript. As I said it will be as simple as possible, just "next and back buttons" no slideshows or such.

    Thanks.
     
    ademmeda, May 9, 2011 IP
  2. ruvenf

    ruvenf Peon

    Messages:
    19
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If you don't use client side scripting like JavaScript, each time you want to change a picture you will have to load the page.
    if you insist (I don't understand why) of not using it, I think you should embed a php page that use an array of pictures like this:
    $pic = array ('pic1.jpg','pic2.jpg',...);
    have the pic location in the url like this: page.php?pic=1
    when the page loads ues get to get the pic numbet $picnum=(int)$_GET['pic'];

    the next button will be if($picnum+1<count($pic))<a = "page.php?pic=<?=$picnum++?>">next</a>
    back will be <?php if($picnum-->0)?> <a = "page.php?pic=<?=$picnum--?>">back</a>
    to present the picture just use: <img src="<?=$pic[$picnum]?>">

    hope it helps
     
    ruvenf, May 9, 2011 IP
    ademmeda likes this.
  3. ademmeda

    ademmeda Active Member

    Messages:
    354
    Likes Received:
    3
    Best Answers:
    3
    Trophy Points:
    70
    #3
    Thanks for the reply. I am designing for mobile devices, that's why I want to do it with simple PHP if it is possible. I will try your code snippets but I am new to PHP and I am not sure if I can compile a working code out of it.
     
    ademmeda, May 10, 2011 IP