trying something new with php and images

Discussion in 'Web Design and Development (archive)' started by brianellisrules, Jan 27, 2004.

  1. brianellisrules macrumors regular

    Oct 17, 2003
    OK, so I have a website (

    On this website, I have various stories, some with pictures.

    I'm in the midst of a new story and I'm trying something new with php. I'm about halfway there...

    Here's what I'm thinking. I have a story... a little writeup. Throughout the story are various links to pictures. Rather than having the person click the links (and leave the story) I want to have them stay put... but, I don't want the pictures showing up when the page loads. So, here's what I devised...
    <p>Here's a nice picture of me... Damn, I was a <a href="?pic=cutekid">cute kid</a>.</p>
    if ($pic==cutekid) {
    echo (
    "<center><img src=\"picture.jpg\"></center>");
    This way, there's the text... the person reads it, the click the link and the picture appears below the line. This actually works! Sort of!

    Right now the page I'm working on has more than one picture, so once another link is clicked, the previously shown picture disappears. This is annoying because the page reloads and the text jumps around and makes it hard to follow.

    Here's a sample:

    Any ideas for a way to get the pics to stay once they're clicked (and other images/links are clicked)?
  2. sonofslim macrumors 6502a


    Jun 6, 2003
    using JavaScript to hide/unhide your images via CSS might be a better way to accomplish this, rather than reloading the page every time an image is selected.

    edit: sorry, that wasn't informative at all! accidentally hit 'post' before i was done... anyway, because html is stateless, you've got no way of retaining those pictures through a reload unless you involve cookies or start passing a variable for each picture you want loaded:
    in which case you'll have to start parsing your URL to find out what images are already loaded and dynamically adding them to your links.

    or i suppose a slightly better way would be to do it all through a form and dynamically add hidden inputs to control which images are loaded... anyway, my point is that it's a mess of work, and you're reloading your page all the time, and it would be easier to do with CSS.

    look into JavaScript's document.getElementById. i've seen you work through your other questions on this site, so i know you can figure it out without too much help from us -- good luck!
  3. fugeelama macrumors member


    Oct 23, 2002
    I do something similar on my website. I basically have a JavaScript that keeps a menu hidden until it's clicked, then it pops open and stays open until it's clicked again to close. The code goes something like this:

    function handleParent(parentId)
            myParent = document.getElementById("menu" + parentId)
            if ("none") {
            } else {
    And then I call it:

     <a href="javascript:handleParent(1)">
    And that's it! I'm sure you can get it to work just fine with showing/hiding images as well.
  4. brianellisrules thread starter macrumors regular

    Oct 17, 2003
    Cool, thanks for the help!

    fugeelama, I swiped your code and changed it up a bit to work for my page... but for some reason, I have to double click on the links to get the images to show up... kind of annoying, but it works.

    Thanks again!
  5. Rower_CPU Moderator emeritus


    Oct 5, 2001
    San Diego, CA
  6. sonofslim macrumors 6502a


    Jun 6, 2003
    but problematic for IE5.x. the article only lists the Windows version of the browser as having problems, but it's also squirrely on the Mac. still, the CSS is impressive.

    and by the way, brian: i meant my "go do it yourself" suggestion as a vote of confidence. i can tell you've have had a lot of fun figuring out how to get your site up and running. you were ready to handle that one yourself, grasshopper.
  7. brianellisrules thread starter macrumors regular

    Oct 17, 2003
    Thanks for the input everyone.

    Rower, I played with it for a bit and I'm not sure that's going to work for what I had in mind. It's pretty dang clever though!

    Sonofslim, I figured that's what you meant... Of course, the reason I never became a programmer was my lack of patience. :) I get frustrated pretty easily... I'm surprised I got my little voting poll to work!

    Thanks again everyone. I'll be sure to post a link of what I'm working on here as soon as it's ready to be released to the world...

Share This Page