Welcome to WebmasterWorld Guest from 50.16.107.222

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP gallery-problem

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

New User

5+ Year Member

joined:Mar 19, 2009
posts: 37
votes: 0


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]

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

Preferred Member

5+ Year Member

joined:Jan 16, 2007
posts:477
votes: 0


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?

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

New User

5+ Year Member

joined:Mar 19, 2009
posts:37
votes: 0


Thanks for the help - it works now (:
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members