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
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
    }

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.