Jump to content

parse error using if and elseif


shmeeg

Recommended Posts

ok so I guess I'm not too good at this :D

 

here's my code:

	<?php echo $_GET["type"]; ?> > 
<?php if $_GET["type")=="player" echo $row["name"]; elseif $_GET["type"]=="team" echo $row["team"]; ?>

 

I dont usually use if and elseif statements, infact, it's the first time I ever have tried it.

 

What I'm trying to do is allow users to see where they are, at the top of the page it should look a little something like

soccerdb > Statistics > Player(if type=player)/Team(if type=team) > player name/team name

 

thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/204010-parse-error-using-if-and-elseif/
Share on other sites

Since there are only 2 options, an "else if" isn't really necessary. "Else" will work just fine.

 

<?php if( $_GET["type")=="player" ) { 
     echo $row["name"]; 
} else { 
     echo $row["team"]; 
} ?>

that solution is also giving me syntax errors.

 

	<br />soccerdb > statistics > 
<?php echo $_GET["type"]; ?> > 
<?php if( $_GET["type")=="player" ) { 
echo $row["name"]; } 
else { echo $row["team"]; } ?>

 

that's the whole piece of code that I have now, error is on line 3 and 5?

 

 

EDIT: found the error in that one, thanks! it works :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.