Forum Moderators: coopster

Message Too Old, No Replies

Easy peasy If loop.

A lil help?

         

wonderboy

11:07 am on Mar 8, 2004 (gmt 0)

10+ Year Member



I have an idea of code of what I want, just wondering what the real thing may look like, and if it would work. The code below goes in header.php, and in index.php $adloader is defined as 1, or not defined at all;

<? If $adloader = "1";
require("ad1.php");
Else
require("ad2.php");
?>

Thanks for your help.

W.

Robber

11:37 am on Mar 8, 2004 (gmt 0)

10+ Year Member



Hi,

Take a look at php.net for how ifs work, but hers a starter for you:

<?
if($adloader === "1"){
include("ad1.php");
}else{
include("ad2.php");
}
?>

Somethings to look at - the conditional test uses === rather than =. A single = assigns rather than compares (leading to big trouble in if tests). You can use == or === but the third tests if something is identically equal, ie same value and same data type. Note how this could impact your test, you have "1", using quotes says the data is a string value rather than numeric, so depending on your script the === could give you issues.

ergophobe

6:24 pm on Mar 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




$adloader is defined as 1, or not defined at all;

If you will turn up error reporting to E_ALL, you'll see that this throws a warning if you use Robber's code.

If possible, have it so $adloader is always defined as in

$adloader = (condition which if true, we load ad)? 1 : 0;

Then in your code

if ($adloader) { do stuff }

If you can't do that, you should test

if (isset($adloader) && $adloader == 1) { do stuff }

This will avoid any PHP warnings

Tom