Jump to content

[ resolved ] saying if this is clicked?


Zeroshade

Recommended Posts

This is my goal. I want a picture to be displayed. If the picture is clicked then the first picture will equal the second picture which then equals a whole new picture and therefore displays the new picture instead. So basically I want a slideshow. Can I do this?
Can this be adapted somehow?

[code]<?php
                                                        $picture = "images\blue-carry.jpg";
                                                        echo "<a href='images\blue-carry.jpg?link=1'><img src='$picture' /></a>";
                                                        if($_GET['link']==1)
{
                                                        $picture = "images\blue-ebook.jpg";
echo "<img src='$picture' />";
}
                                                ?>[/code]
I would recommend that you store the image paths in a numbered array, and increment through them one by one as the images are clicked.

Here's an example:

[code]
<?php

$photos = array (1=>'img/photo_1.jpg', 'img/photo_2.jpg', 'img/photo_3.jpg', 'img/photo_4.jpg');

$curPic = $_GET['id'] + 1;

if ($curPic < 5)
   echo '<a href="slideshow.php?id=' . $curPic . '"><img src="' . $photos[$curPic] . '" /></a>';
else
   echo '<p>End of Show</p>';

?>

[/code]

The id displayed in the URL will be one behind the index of the picture actually being displayed.  If that bothers you, then you can modify where you actually increment your index value.  In case it isn't obvious, replace 'slideshow.php' with whatever you name your php file.
I'm not understanding the link. If i point it to the slideshow.php then it opens up a new page. if i take it out like so... it'll refresh the page with the new picture. How can i keep it from acutally refreshing?
[code]<?php
                                                        $picture = array (1 => 'images\blue-carry.jpg', 'images\blue-ebook.jpg');
$curPic = $_GET['id'] + 1;
if ($curPic < 3)
echo '<a href="?id='.$curPic.'"><img src="'.$picture[$curPic].'" /></a>';
else
  echo '<p />End of Show';
                                                ?>[/code]
[quote]How can i keep it from acutally refreshing?[/quote]

You cant. A request needs to be made to the server and the server needs to send the response. Of course you could use some Ajax trickery but thats a whole other beast not really in the scope of this forum.

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.