Jump to content

Dynamically changing image


oha055

Recommended Posts

Hi!

 

I am currently making a really simple photo blog. The query fetches every reference to the images which are stored on the server. I have a problem when it comes to dynamically cycling through these though.

 

After running the query, I store each image reference in a twodimensional array like this: [["id"], ["date"], ["title"], ["filename"]] (an Array of Arrays).

 

The image displays just fine by doing this:

 

$pointer; //starting from the last element (image) in the array

 

<img src="images/gallery/<?php echo $images[3][$pointer] ?>" alt="<?php echo $images[2][$pointer] ?>">

 

The problem is that, when I update the pointer, say for instance pointer++, the current image on the screen doesnt update. I know for a fact that the pointer updates, because I have echoed it.

 

The basic idea is to have a previous and next link just under the image, so that the viewer can cycle the available images.

 

Any help is greatly appreciated :)

Link to comment
https://forums.phpfreaks.com/topic/256386-dynamically-changing-image/
Share on other sites

Got it working! :) This is the code. I am new to PHP so feel free to comment if there are other, better ways of doing this :)

 

    private function showBlog() {
        $imageId = count($this->_filenames) - 1;
        if (isset($_GET['id'])) {
            $imageId = $_GET['id'];
        }
        ?>
        <center><img src="images/gallery/<?php echo $this->_filenames[$imageId]; ?>" /></center>
        <div id="navigation">
            <div id="prev">
                <a href="?id=<?php echo $imageId - 1; ?>">prev</a>
            </div>
            <div id="next">
                <a href="?id=<?php echo $imageId + 1; ?>">next</a>
            </div>
        </div>
        <?php
    }

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.