Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Display array items one at a time?

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #26759
    Element
    Member

    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?

    #66611
    TeMc
    Member

    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.

    #66736
    Element
    Member

    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!

    #66737

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

    #66741
    Element
    Member

    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)
  • The forum ‘Back End’ is closed to new topics and replies.