Jump to content

display images sequentially using PHP and MySQL

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
jhanjon

jhanjon

    Newbie

  • Members
  • Pip
  • 3 posts
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 it does increment the id requested. Please help??



Here's the portion of the code in question and the html is a print request on the same page:

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

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

 

// main portion of script with problem

$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))
   $row = mysql_fetch_assoc($image);
   {
         //set up integer counting of items in folder
          $i = intval($row['i']);
          $c = 0;
          $p = $row['folder']."/".$row['location'];
          if ($i==$c)

            $c++;

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

               print

// the + (plus sign) is a hyperlink for the next image id and the - (minus sign) is for the previous one
               "<a href=\"player.php?i=$i1\">-</a> "
               ."<img src=\"$p\" border=\"0\" width=\"$width\" "
               ."<a href=\"player.php?i=$i2\">+</a><br\>\n";
              }


}


#2
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Thread move to correct section. Please don't post questions in the tutorial sections. Also, please use code tags. It makes it easier for us to read your code.

Why do you have an opening bracket after:

   $row = mysql_fetch_assoc($image);
I imagine this is left over from removing your while loop? Because you have no loop, $i1 will always be 0. $i2 will always be 2.

Where do you pull the $_GET value i from? Can we see that code?

#3
jhanjon

jhanjon

    Newbie

  • Members
  • Pip
  • 3 posts

Jordan said:

Why do you have an opening bracket after:

   $row = mysql_fetch_assoc($image);
I imagine this is left over from removing your while loop? Because you have no loop, $i1 will always be 0. $i2 will always be 2.

Where do you pull the $_GET value i from? Can we see that code?

Thank you for relocating to the correct place and I will look for the code tags as well.

The i was set to display integer so as to allow a "next" and "before" scenario so I'm not sure how to set a $_GET value for it. I'm a newbie and really open to ideas even if it means an overhaul.

In the status bar of the browser I can see that the $i1 becomes an href calling for player.php?i=2 when hovering over my "plus" sign so I thought it was responding OK. The thing is the resultant image is missing since it is simply pointing to localhost root hence nothing being fetched. The primary first image $p shows up nicely however.

The open curl is a leftover, thanks.
//full code here

<?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))

  $row = mysql_fetch_assoc($image);

 //  {



        //set up integer counting of items in folder

          $i = intval($row['i']);

          $c = 0;

          $p = $row['folder']."/".$row['location'];

          if ($i==$c)


            $c++;


              if (strlen($p)>0)

              {

              $i1 = ($i+$c-1);

              $i2 = ($i+$c+1);


               print


               "<a href=\"player.php?i=$i1\">-</a> "

               ."<img src=\"$p\" border=\"0\" width=\"$width\" "

               ."<a href=\"player.php?i=$i2\">+</a><br\>\n";

              }



//}


?>