Connecting Tech Pros Worldwide Forums | Help | Site Map

Display image if variable set to true

Newbie
 
Join Date: Feb 2007
Posts: 12
#1: Apr 13 '07
I'm making a website for a friend and am wondering about the best way to do something.

It's a flat site and he wants the ability to disable a banner advert without editing all the pages. I thought the best way to do this is have a file somewhere with a variable set to true then have a bit of php in the <div> on his site that will only display the ad if this variable is set to true.

Am i right in thinking i can put the following in the top of every page

Expand|Select|Wrap|Line Numbers
  1. <?php include_once('ad_switch.php'); ?>
and then something like the following in the div that holds the banner

Expand|Select|Wrap|Line Numbers
  1. <?php if ($adswitch = true) { image goes here ;} ?>
The problem i'm having is that the image is constantly displaying and i can't get it to bugger off no matter what the $adswitch variable is set to.

Thanks

Newbie
 
Join Date: Feb 2007
Posts: 12
#2: Apr 13 '07

re: Display image if variable set to true


Silly question but will adding an else fix it?
code green's Avatar
Expert
 
Join Date: Mar 2007
Location: England
Posts: 1,083
#3: Apr 13 '07

re: Display image if variable set to true


I am assuming the $adswitch variable is creates in 'ad_switch.php'. This variable goes out of scope as soon as 'ad_switch.php' ends. Therefore your statement[PHP] <?php if ($adswitch = true) { image goes here ;} ?> [/PHP] is instaniating a new variable which (and this catches the unwary out) is TRUE by default.
Reply