Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

brianellisrules

macrumors regular
Original poster
Oct 17, 2003
229
0
OK, so I have a website (http://www.brianellisrules.com).

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...
PHP:
<p>Here's a nice picture of me... Damn, I was a <a href="?pic=cutekid">cute kid</a>.</p>
<?php
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:
http://www.brianellisrules.com/temp/sample.php

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

sonofslim

macrumors 6502a
Jun 6, 2003
742
0
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:
Code:
url.php?pic1=on&pic2=on&SoOnAndSoForth
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!
 

fugeelama

macrumors member
Oct 23, 2002
57
0
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:

Code:
function handleParent(parentId)
{
        myParent = document.getElementById("menu" + parentId)

        if (myParent.style.display=="none") {
                myParent.style.display="block"
        } else {
                myParent.style.display="none"
        }
}

And then I call it:

Code:
 <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.
 

brianellisrules

macrumors regular
Original poster
Oct 17, 2003
229
0
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!
 

sonofslim

macrumors 6502a
Jun 6, 2003
742
0
Originally posted by Rower_CPU
Here's a non-javascript route you can try, too. It's not PHP either, but it is some tasty CSS.

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.
 

brianellisrules

macrumors regular
Original poster
Oct 17, 2003
229
0
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...
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.