Jump to content

Can I do a $_GET without refreshing the screen?


kls1974

Recommended Posts

Hi.
I-m trying to make a simple image gallery and I don't want to use javascripts or frames (iframes) so PHP is the way to go (I think), so I spend the last 3 days trying to learn PHP programming and have a few problems?

I need a gallery with thumbs in a vertical row with a scrollbar and a full size image in the center of the page (fixed)

I made a simple script where I use <a href="gal.php?pic=...> on the thumbs and then use <img src=" $_GET['pic'] "> to show the file and it works great but the screen refreshes and scrolls to the top of the screen/scrollbar!
This is bad because you have to scroll down to click the next thumb every time?

Is there any way other than GET to make this kind of gallery or a way not to refresh the screen on link click?

Here's the PHP file (gal.php):

[code]
<?php
$thumbs = "tmb/";
$pics = "pic/";

if ($handle = opendir($thumbs)) {
  while (false !== ($file = readdir($handle))) {
      if ($file != "." && $file != "..") { $files[] = $file; } }
  closedir($handle); }

sort ($files);
foreach($files as $file) { echo '<a href="gal.php?pic=' . $file . '"><img src="' . $thumbs . $file . '" /></a><br>'; }

if ($_GET['pic'] == NULL) { echo "no picture chosen <p>"  ;}
else {echo '<p><img src="' . $pics . $_GET['pic'] . '" style="position: fixed; left: 50%; top: 50%; margin-left: -320px; margin-top: -240px"><p>';}
?>
[/code]
im not too sure how you could do that but what you could do is have it like that and set the pic in <p> tags with an id that you can add to the href so it will auto scroll to that image.. like
<p id="image"><a href="gal.php?pic=...#image> <img src=""></p>
Thanks, it works  :)

I changed the foreach() section to:

foreach($files as $file) {
[b]$tmptag = strlen($file)-4;
$tag = substr($file, 0, $tmptag);[/b]
echo '<a name="' . $tag . '" href="gal.php?pic=' . $file . '#' . $tag . '"><img src="' . $thumbs . $file . '" /></a><br>'; }

But it would be nicer if I could use some other POST method so the screen wouldn't have to be reloaded as with the <a href....> command?

Is there any other way that I can do this? (assing a value to [i]$pic[/i] by clicking on a image thumbnail and use this value to change the displayed image (<img src="path/' . [i]$pic[/i] . ' "/>) and updating just the image without refreshing the screen?)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.