if/elseif statements

Just wondering if someone could quickly review this code for me.

No matter which value $trainer holds, $trainer_price always comes out as 39.99.

[php]
$trainer = $_REQUEST[‘trainer’];

	if ($trainer == "1") {
		$trainer_price = 59.99;
	}
	elseif ($trainer == "2") {
		$trainer_price = 54.99;
	}
	elseif ($trainer == "3" || "4") {
		$trainer_price = 39.99;
	}
	elseif ($trainer == "5") {
		$trainer_price = 34.99;
	}
	elseif ($trainer == "6" || "7") {
		$trainer_price = 29.99;
	}
	elseif ($trainer == "8") {
		$trainer_price = 24.99;
	}[/php]

Hi there,

I think you’ve misunderstood the use of || in an if statement. It does not continue your statement, rather join it with another. For example:
[php]if ($trainer == “3” || “4”)[/php]
means:
[php]if ($trainer == “3”) OR if(“4”)[/php]

You will need to change your statements that follow the above syntax to this layout:
[php]if ($trainer == “3” || $trainer == “4”)[/php]

Hope this helps.

Sponsor our Newsletter | Privacy Policy | Terms of Service