Welcome to WebmasterWorld Guest from 54.242.94.72

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP gallery-problem

     

geeklike

11:27 am on Jun 2, 2009 (gmt 0)

5+ Year Member



I'm making a PHP gallery atm, where it is supposed to go from pic1 to pic 2 and so on when you click next or previous. However, while the links work, the picture never changes :/ Can anybody help, please?

Here is the PHP;

include('inc/db_connect.inc');

$gallery_query="SELECT * FROM gallery ORDER BY gal_id ASC";
$gallery_result=mysql_query($gallery_query);
$gallery_data = mysql_fetch_assoc($gallery_result);
mysql_data_seek($gallery_result,0);

$image = $gallery_data['gal_img'];
$size = getimagesize($image);
$height = $size[1];
$width = $size[0];

if ($height > 245) {
$width = ($width * 245 / $height);
$height = 245;
}

while ($width > 345) {
$height = ($height * 345 / $width);
$width = 345;
}

$imgno = $gallery_data['gal_id'];

if (isset($gallery_data['gal_id']))
{$imgno = intval($gallery_data['gal_id']);
}

$imagedisplay = "<a href='" . $gallery_data['gal_img'] . "' target='_blank'><img src='" . $gallery_data['gal_img'] . "' width='" . $width . "' height='" . $height . "' border='0px'/></a>";
if ($imgno>1)
{$previmgno = $imgno-1;
$linkprevious = "<a href=\"?gal_id=" . $previmgno . "\">Previous</a>";
}
else
{$linkprevious = "<s>Previous</s>";
}
if ($imgno<10000)
{$nextimgno = $imgno+1;
$linknext = "<a href=\"?gal_id=" . $nextimgno . "\">Next</a>";
}
else
{$linknext = "<s>Next</s>";
}

Any help is great, thanks!

[edited by: eelixduppy at 2:26 pm (utc) on June 2, 2009]
[edit reason] no personal urls please TOS [webmasterworld.com] [/edit]

d40sithui

4:36 pm on Jun 2, 2009 (gmt 0)

5+ Year Member



A few things...

1) I don't see the part where you retrieve the image id/ gallery id from the URL. You provide a "previous" and "next" link, but if you do not process this data, nothing will change and as you see, it will always display the same image.
Somewhere in your script, you should have something like


$currentGalId = $_GET['gal_id'];

$gallery_result = mysql_query("SELECT gal_img FROM gallery WHERE gal_id=$currentGalId");
$gallery_data = mysql_fetch_assoc($gallery_result);
$image = $gallery_data['gal_img'];
//display image here

2) Your pagination could be improved to avoid using static variables to control previous/next buttons. Also, think about if you have 100 images or so and the user's on the 50th image. What would you display for the previous 5 or next 5 image thumbnails? And how would you code that?

geeklike

10:26 am on Jun 3, 2009 (gmt 0)

5+ Year Member



Thanks for the help - it works now (:
 

Featured Threads

Hot Threads This Week

Hot Threads This Month