Forum Moderators: coopster

Message Too Old, No Replies

PHP? Can I Do This?

Changing An Image.

         

andmunn

2:31 am on Mar 19, 2005 (gmt 0)

10+ Year Member



This may seem like an over convuluted explanation, but let me explain.

My main page consists of the body (.php) page, and a footer include (.html) and a header include (.html)

Now, i want to set some variables in the body (.php page), so that a certain image will change in the header (.html).

I.E.// i want to change the image displayed at the top of the page, so that it corresponds to the body of the page.

For example, i have two images: car.gif, and bus.gif.

I'm on on the main page of cars, car.php, i want it to pull a "car.gif" image into the header.html file (the header is never changed for any pages).

If i'm on the main page of buses, bus.php, i want it to pull a "bus.gif" image into the header.html file.

The header file never changes, but IMAGES in the header file need to change because of the changing gif files as specified in the body of the php page.

Does this make sense? Is this possible? Any suggestions?

Andrew.

bluedalmatian

2:58 am on Mar 19, 2005 (gmt 0)

10+ Year Member



yes set a variable at the start of your main page e.g

$topic = "cars";

then in the header insert the following, well youll probably need to modify the filename but you get the gist:

<?php
if ($topic == "cars")
{
print "<img src='car.gif'>";
}
else if ($topic == "bus")
{
print "<img src='bus.gif'>";
}
?>

It doesnt matter that the header has the .html extension because it will be imported first, becoming part of the main .php file, thus any PHP code in it will get executed, and because it becomes part of the main file, any variables already set in the main file, before the include, are available.

andmunn

3:01 am on Mar 19, 2005 (gmt 0)

10+ Year Member



Ah, simple as pie - that makes perfect sense. Worked like a charm. Never thought to use "if" statements. Thanks again.

Andrew.

orion_rus

2:44 pm on Mar 19, 2005 (gmt 0)

10+ Year Member



I advice you to use templates such as obtemplate!
Good luck to you!