Page 1 of 1

[SOLVED] if statement changing value

Posted: Wed Sep 29, 2004 1:22 pm
by sell-traffic
Hi,

The code below should check the value from a URL variable, and then return a text string determined by what the URL is. This should be simple...

Code: Select all

<?php
$targeting = $_POST['targeting'];
$cpmimpressions = $_POST['CPM'];
echo $targeting;
if ($targeting = 1.5)
	{
	$targetingname = "Non-Targeted Popunders";
	}
elseif ($targeting = 2)
	{
	$targetingname = "Language-Targeted Popunders";
	}
elseif ($targeting = 2.5)
	{
	$targetingname = "Country-Targeted Popunders";
	}
elseif ($targeting = 3)
	{
	$targetingname = "Language and Category-Targeted Popunders";
	}
elseif ($targeting = 3.5)
	{
	$targetingname = "Country and Category-Targeted Popunders";
	}
echo $targeting;

?>

The first echo $targeting returns the correct value. But when it gets toe end the echo $targeting always returns 1.5.

Forgive my stupidity here, I'm a windows programmer, not a php programmer (yet). Why is the if statement changing the value of my $targeting variable??

Thanks,

Josh

Posted: Wed Sep 29, 2004 1:27 pm
by vigge89
if you usethe assignment operator (0), it returns true if its set, otherwise false. Change all the if ($var = $othervar) to if ($var == $othervar) to make it work ;)

RESOLVED

Posted: Wed Sep 29, 2004 1:44 pm
by sell-traffic
Resolved. Changed to switch (That's what I was looking for anyway).

Code: Select all

<?php
switch ($targeting)
	{
	case "1.5":
		$targetingname = "Non-Targeted Popunders";
		break;
	case "2":
		$targetingname = "Language-Targeted Popunders";
		break;
	case "2.5":
		$targetingname = "Country-Targeted Popunders";
		break;
	case "3":
		$targetingname = "Language and Category-Targeted Popunders";
		break;
	case "3.5":
		$targetingname = "Country and Category-Targeted Popunders";
		break;
	}

?>