Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If Else for include 1

Status
Not open for further replies.

A1Pat

IS-IT--Management
Jun 7, 2004
454
US
hello all,

I'm a new learner in PHP, and this is my problem

<?
if ($_SESSION['language']="en")
include("htmltop_en.html");
elseif
include("htmltop_vn.html");
?>

PHP doesn't seem to understand this If... Else

thanks.
 
PHP does have the elseif function. But that's not what you want. You want to use just "else" here.

Elseif requires that you provide another condition:

[tt]if (foo == 3)
{
//do one thing
}
elseif (foo == 4)
{
//do another thing
}[/tt]


Personally, I intensely dislike the elseif construct and have never found a situation where code readability could not be improved through the use of nested if-statements or a switch statement.



Want the best answers? Ask the best questions! TANSTAAFL!
 
First of all comparisons on PHP are done witrh 2 "=" equal signs so
Code:
<?
if ($_SESSION['language']="en")
should be
if ($_SESSION['language']=="en")

Second alwasy enclose your your IF statements in curly braces:
Code:
if ($_SESSION['language'][blue]==[/blue]"en")[red]{[/red]
   include("htmltop_en.html");
[red]}[/red]
elseif[red]{[/red]
   include("htmltop_vn.html");
[red]}[/red]
?>

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Right Sleipnir, elseif requires a condition, howd i miss that.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
aha... I got it now, thanks to vacunita on the point "=="

and I also want to apology for the typo error "elseif". I intended to write ELSE. Sorry again!!! thank you all.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top