else/elseif question

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
mrlayance
Forum Commoner
Posts: 31
Joined: Mon Dec 07, 2009 11:53 am

else/elseif question

Post 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;
neojawbreaker
Forum Newbie
Posts: 3
Joined: Mon Jul 19, 2010 7:25 pm

Re: else/elseif question

Post 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;}
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: else/elseif question

Post by Jonah Bron »

One = sign is an assignment. You need double equal signs (==) for conditional statements.
Post Reply