Grow your CSS skills. Land your dream job.

Display array items one at a time?

  • # November 14, 2009 at 3:31 pm

    PHP beginner here. I’ve written a (probably lousy) function to pull file (image) names from a folder and store them in an array, and then loop through the array according to which array the visitor chose to display… um. That made no sense; check this out instead:

    http://labs.elementalley.se/stuff/wth/

    And here’s the code:
    http://labs.elementalley.se/stuff/wth/index.phps
    http://labs.elementalley.se/stuff/wth/view.phps

    Now, what I want to do is not display the images all at once, but start with the first one and let the user click a button when they want to see the next one. Not too complicated (I think?) but I don’t even know where to begin. I had some vague idea about using isset() to see if "bildserie" had been set to anything, and then somehow… displaying the next array item… when the user clicked a button that… and then I’m lost. Help? A nudge in the right direction?

    # November 15, 2009 at 12:54 am

    I have very quickly read a bit through your code, but here’s a short answer I think should work:

    * set $number = $_GET;
    * make a default ( if (empty($number)) { $number = 0; } *
    * then instead of the foreach do:
    $image = displayArray[$number];

    After you’ve echo’ed the image. Make a link:

    Code:
    Code:


    TeMc

    * I know that ’0" is also considerd "empty", but that doens’t really matter in this case.

    # November 17, 2009 at 7:22 pm

    Thanks for your help – I didn’t quite get it to work, but you set me on the right track. With a little help from another source, this is what I ended up with:

    http://labs.elementalley.se/stuff/wth/new.php

    Code:
    http://labs.elementalley.se/stuff/wth/new_view.phps

    Thanks again!

    # November 17, 2009 at 7:24 pm

    Good stuff! It’s always better when you find your own solutions, we just sometimes need a hint on where to look!

    # November 17, 2009 at 8:05 pm

    Yeah, finding solutions – I think I’ve been bitten by the code bug. The good kind of bug, where you get all absorbed and forget about things like eating and the hours passing. I know this is very basic, but it’s been FUN. :)

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".