I have the following code to fetch images from an SQL data where a "gallery" id is set and a "artworks" id is set. BTW the "artworks" is really the images which I want to display. I am able to display the first image OK, however the "next" and "before" images don't show up although the URL status does increment the id requested.

I only want one image at a time incremented by a mouse action for "next" and "previous."

//display gallery name for use from the referring page where the gallery is selected

<?php
include("design/header.php");
require("connect.php");

$galleryid = $_GET['gallery'];
$id = $_SESSION['id'];

//display gallery name
$gallery = mysql_query("SELECT gallery_name FROM galleries WHERE id='$galleryid'"); $galleryarray = mysql_fetch_assoc($gallery);

echo "<table width='220' cellpadding='7'> <tr> <td>
    <br><br><font size='5' face='verdana' color='#006600'>".$galleryarray['gallery_name']."</font><br>
    <font size='2' face='verdana'><a href='managegalleries.php'><b>Return </b></a>to Galleries Admin</font> </td> </tr> </table>";

$image = mysql_query("SELECT * FROM artworks WHERE userid='$id' AND galleryid='$galleryid'"); $folder = mysql_query("SELECT * FROM artworks WHERE userid='$id' AND galleryid='$galleryid'");


  if ((mysql_num_rows($image)<=0))
   echo "Sorry that gallery doesn't exist!";


 while ($row = mysql_fetch_assoc($image))  //currently displays all the images 
// $row = mysql_fetch_assoc($image); //returns one image as $p below but no looping
  {

        //set up integer counting of items in folder but it doesn't fetch a next and previous
          $i = intval($row['i']);
          $c = 0;
          $p = $row['folder']."/".$row['location']; //$p gets the one image returned if not using the while statement
          if ($i==$c)

            $c++;

              if (strlen($p)>0)
              {
              $i1 = ($i+$c-1); //$i1 decrements OK 
              $i2 = ($i+$c+1); //$i2 increments OK

               print

               "<a href=\"player.php?i=$i1\">-</a>&nbsp;"
               ."<img src=\"$p\" border=\"0\" width=\"$width\" "
               ."<a href=\"player.php?i=$i2\">+</a><br\>\n";
              }


}

?>

hey what is the need for doing the below thing twice -

$image = mysql_query("SELECT * FROM artworks WHERE userid='$id' AND galleryid='$galleryid'"); 
$folder = mysql_query("SELECT * FROM artworks WHERE userid='$id' AND galleryid='$galleryid'");

hey what is the need for doing the below thing twice -

$image = mysql_query("SELECT * FROM artworks WHERE userid='$id' AND galleryid='$galleryid'"); 
$folder = mysql_query("SELECT * FROM artworks WHERE userid='$id' AND galleryid='$galleryid'");

No reason, you are right but I'm new to PHP anyhow it resulted from my separating the folder from the image location but commenting it out is the same as my issue is how to display one image at a time on the page and not all the rows result. So I need an event like a mouse click "next" and "previous" to engage the next image and how to fetch it.

ok, if i got you right, you want to create the image gallery in php with displaying one default image at first.And then with some navigation features like next and prev.
This is to be done with the javascript,
Now you can move your thread to the javascript to get commented on it for that process in easy way or you can achieve the same using the some prebuild gallery code done in jQuery like -
http://jqueryfordesigners.com/slider-gallery/
or http://phplug.net/components/javascript/jquery-gallery.html etc and lots more.
Best luck

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.