Page 1 of 1

else/elseif question

Posted: Tue Sep 28, 2010 12:50 pm
by mrlayance
Not sure why this is not working? The first else shows up on everything?

Code: Select all

$div = substr($base, 1);
	if ($div = "1"):
		echo "<a href=\"http://511.gov.ns.ca/map/\" target=\"_blank\">Nova Scotia Road Conditions</a><br/>\n";
		echo "<a href=\"http://511.gov.ns.ca/map/\" target=\"_blank\">Nova Scotia Traffic Cameras</a><br/>\n";
	elseif($div = "2"):
		echo "<a href=\"http://www.roads.gov.nl.ca/winterdriving/default.stm\" target=\"_blank\">Newfoundland Road Conditions</a><br/>\n";
		echo "<a href=\"http://www.roads.gov.nl.ca/cameras/Default.stm\" target=\"_blank\">Newfoundland Traffic Cameras</a><br/>\n";
	elseif ($div = "3"):
		echo "<a href=\"http://nb.telenium.ca\" target=\"_blank\">New Brunswick Road Conditions</a><br/>\n";
		echo "<a href=\"http://www.gnb.ca/0113/cameras/index-e.asp\" target=\"_blank\">New Brunswick Traffic Cameras</a><br/>\n";
	elseif ($div = "4"):
		echo "<a href=\"http://www.gov.pe.ca/roadconditions/index.php3\" target=\"_blank\">New Brunswick Road Conditions</a><br/>\n";
		echo "<a href=\"http://www.gov.pe.ca/roadCameras/\" target=\"_blank\">New Brunswick Traffic Cameras</a><br/>\n";
	else:
		echo "Not sure of your Div";
	endif;

Re: else/elseif question

Posted: Tue Sep 28, 2010 12:53 pm
by neojawbreaker
Using = means you are setting something equal to something else.

You need to use == which is the comparision operator. For example. . .

$var = 5;

if ($var == 5) {echo $var;}

Re: else/elseif question

Posted: Tue Sep 28, 2010 12:54 pm
by Jonah Bron
One = sign is an assignment. You need double equal signs (==) for conditional statements.