[SOLVED] if statement changing value

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
sell-traffic
Forum Commoner
Posts: 26
Joined: Thu Aug 05, 2004 9:35 pm

[SOLVED] if statement changing value

Post 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
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post 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 ;)
sell-traffic
Forum Commoner
Posts: 26
Joined: Thu Aug 05, 2004 9:35 pm

RESOLVED

Post 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;
	}

?>
Post Reply