homepage Welcome to WebmasterWorld Guest from 54.163.72.86
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
PHP gallery-problem
geeklike




msg:3924697
 11:27 am on Jun 2, 2009 (gmt 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]

 

d40sithui




msg:3924880
 4:36 pm on Jun 2, 2009 (gmt 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?

geeklike




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

Thanks for the help - it works now (:

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved