Image gallery $id count

Hi there,

I am currently working on an image gallery, using php to go through a directory, and to display a ‘next’ and ‘previous’ button… however the ‘next’ button does not add +1 to the $id as I would like it to do… please help.

Here is my code:
(sorry for link, but sitepoint tells me ‘new users cannot put images in post’, even though is not the case :/)

This is the link to where i’m testing:

i ve tried the following so far:

  • replace request with $_GET[‘$id’] … no change
  • $id = 2 to start … doesn’t even display the ‘previous link’

any help would be appreciated

Try this:

// Variables
  $first  = 1;
  $last   = 6;
  $jpgdir = "./img/beleuchtung";   
  $self   = $_SERVER['PHP_SELF']."?id=";

  $id   = (isset($_GET["id"])) ? $_GET["id"] : 1;
  $next = ($id < $last)  ? $id+1 : $id;
  $prev = ($id > $first) ? $id-1 : $id;
  $img  = "$id.jpg";
  echo $header = '
  <!doctype html>
  <style type="text/css">
    #main {width:88%; margin:1em auto; text-align:center;}
    td {margin: 1em; padding: 1em}
<h1>Lights and Lamps Gallery</h1>
  <div id="main">
      <img src="<?php echo $img;?>" alt="#" />
      <br />
      img = <?php echo $img;?>
      <br />

          <a href="<?php echo $self .$next;?>">  NEXT </a>
          [ <?php echo $id;?> ]
          <a href="<?php echo $self .$prev;?>">  PREV </a>
  </div><!-- id=main -->

awesome John, this works how i wanted it to…

can i also change to $img = $_SERVER[‘PHP _SELF’].$id.jpg ?

and remove the variable $self ?

1 Like

oh, no i can’t, just seen it s the image directory to which it is pointing…

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.