Passing PHP variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
calrockx
Forum Newbie
Posts: 6
Joined: Mon Apr 28, 2008 11:32 am

Passing PHP variables

Post by calrockx »

I've got an external file that sets a DIV background as

Code: Select all

 
background: url('http://vitanova.charlesrubinoff.com/_other/includes/big_pic_image.php') center center;}
 
And the code in that php file is this:

Code: Select all

 
<?php
 
if (!$_GET[image]) {
        $image = "http://vitanova.charlesrubinoff.com/sections/_other/image.php/?width=600&height=450&image=/sections/$_GET[section]/_cover/cover.jpg"; }
    else {
        $image = "http://vitanova.charlesrubinoff.com/sections/'.$_GET[section].'/'.$_GET[category].'/'.$_GET[image].'"; }
            
header("Content-type:image/jpeg");
readfile("$image");
            
?>
 
The idea is that when a user clicks a particular link, a corresponding image will then be assigned to be the background image of that div. Basically, it's a thumbanail gallery linking to full size images, and I want that full size image to be the background of that div.

The problem is that the big_pic_image.php file isn't "seeing" the query string in the URL, so it doesn't know which link was clicked and then which image to show. The
The CSS file just sees the background set to http://vitanova.charlesrubinoff.com/_ot ... _image.php, but I need that file to then show the particular image based on what a user clicked.

Any ideas?
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Passing PHP variables

Post by jaoudestudios »

You could write your CSS in a php file, that way you would have more control over it - but in this situation it might be over kill.

Have you thought about using javascript to make the change, that way it would not reload the page. Take a look at Jquery it is amazing! You can do a lot with minimal effort
calrockx
Forum Newbie
Posts: 6
Joined: Mon Apr 28, 2008 11:32 am

Re: Passing PHP variables

Post by calrockx »

I've thought about making the .css file a .php file.
So then I'd just put all the code from big_pic_image.php into the css-php file, and that'd be it?


The jquery solution sounds interesting, but don't know where to even start with that, and kinda need this sorted out by tomorrow.

I thought there would be a way to tell this php file to check the current url and use the query variables from that for the if-else statement below.
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Passing PHP variables

Post by jaoudestudios »

Unfortunately I cant see how your method is going to work, especially with using header and readfile, think that is over complicating it.

Jquery is really easy, I only started learning it 2 weeks ago and already I have converted 2 websites to use ajax but also downgrade gracefully. I would spend 1 hour looking at Jquery it would be time well spent. The documentation online and examples are excellent. You should be able to achieve what you want in a couple of hours for someone who has never touch Jquery before.

The only thing is you would have to get your site to work with php only to make it downgrade gracefully. But if you were happy for it just to work if a user has javascript turned on, then ditch your php solution for this part?

If you do decide to just use jquery for this part let me know I should be able to write you an example to do what you want.

Wait a second I have just noticed something in your php (but might not be enough to make it work), after your conditional statement echo out your $image, do you get the path you want including the image?
Post Reply