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: http://www.roy.lu/hurt/test.txt
(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:
http://www.roy.lu/hurt/test.php

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:

<?php
// 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  = "http://www.roy.lu/hurt/img/beleuchtung/$id.jpg";
  
  echo $header = '
  <!doctype html>
  <html>
  <head>
  <title>Lights</title>
  <style type="text/css">
    #main {width:88%; margin:1em auto; text-align:center;}
    td {margin: 1em; padding: 1em}
  </style>
  </head>
  <body>
  ';
?>
<h1>Lights and Lamps Gallery</h1>
  
  <div id="main">
    <p>
      <img src="<?php echo $img;?>" alt="#" />
      <br />
      img = <?php echo $img;?>
      <br />
    </p>

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

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.