title: Echo one image from mysql with next/prev button
body: <p>So I have upload form wich uploads image to foldar and save name to database(mysql). So far I have this:</p>
  
  <pre><code>&lt;?php
  
  mysqli_query($connection, "SELECT * FROM images LIMIT 1");
  $result = mysqli_query($connection, $sql) or die ("SQL Error: ".mysqli_error($connection));
  
  while($row = mysqli_fetch_array($result)){
  echo "&lt;div class=\"picture\"&gt;";
  echo "&lt;p&gt;";
  
  echo "&lt;img src=\"upload/" . $row['filename']  . "\" alt=\"\" /&gt;&lt;br /&gt;";
  echo $row['caption'] . "&lt;br /&gt;";
  echo "&lt;/p&gt;";
  echo "&lt;/div&gt;";
  }
  ?&gt;
  </code></pre>
  
  <p>How can I change the code to show me one image at the time.. Like sort of gallery with buttons 'next' and 'prev' to change images?
  In DB I store only 'id' and 'filename'.
  Thanks </p>
  
  <p>edit:
  I made it like this</p>
  
  <pre><code>&lt;?php
  if (isset($_GET['id'])) {
   $id = $_GET['id'];
  } else {
  $id = 1;
  $res=mysqli_query($connection, "select * from images order by id ASC LIMIT  $id, 1");
  $prevSQL = mysqli_query($connection, "SELECT * FROM images WHERE id &gt; '".$id."' LIMIT  1");
  $nextSQL = mysqli_query($connection, "SELECT * FROM images WHERE id &lt; '".$id."' LIMIT 1");
  
  $row = mysqli_fetch_array($res);
  if($prevSQL === FALSE) {
      die("SQL Error: " . mysqli_errno($connection));
  }
  if($nextSQL === FALSE) {
      die("SQL Error: " . mysqli_errno($connection));
  }
  if(mysqli_num_rows($prevSQL)&gt;1){
  $prevRow = mysqli_fetch_array($prevSQL);
  $prev = '&lt;a href="show.php?page='.$prevRow['id'].'"&gt;Prev&lt;/a&gt;';
  
  } else {
  $prev = 'Prev';
  }
  if(mysqli_num_rows($nextSQL)&lt;1){
  $nextRow = mysqli_fetch_array($nextSQL);
  $next = '&lt;a href="show.php?page='.$nextRow['id'].'"&gt;Next&lt;/a&gt;';
  
  } else {
  $next = 'Next';
  }
  echo "&lt;img src=\"upload/" . $row['filename']  . "\" alt=\"\" /&gt;&lt;br /&gt;";
  echo $row['caption'] . "&lt;br /&gt;";
  echo "&lt;/p&gt;";
  echo "&lt;a href='show.php?page=".$id."'&gt;Next&lt;/a&gt;";
  echo "&lt;br/&gt;";
  echo "&lt;a href='show.php?page=".$id."'&gt;Prev&lt;/a&gt;";
  echo "&lt;/div&gt;";
  }
  ?&gt;
  </code></pre>