if and else syntax

Hi everyone,

My problem is trying to make the if and else work conditions work as I want.

I have stated the conditions for the if. However even when I stated the conditions for the else, both the ‘if’ and the ‘else’ appear on the page.

If anyone would take a look at the code for me I’ll post it up.

Thank you


Post it up…

Can’t do much without it.

Please note, that you probably don’t need to post the ENTIRE block of code for the given page, just the part that you need help with. If we need more we will ask.

Also please take note of the posting guidelines at http://www.phphelp.com/phpBB2/viewtopic.php?t=2752

Post some code please. It’s probably a simple syntax problem as I’ve never seen basic language constructs fail ;)

 if ($blocks = theme_blocks("left")) {
    $output .= "   <td id="sidebar-left">$blocks</td>n";
$output .= "   <td id="main">n";
This is followed by variables for 'main' and then ending with

$output .= " </td>n"; }

followed by the else condition

else $output .= " <td id="2cols">n";

Well first of all you should note that [size=99px]=[/size] (single equals sign) is the ASSIGNMENT operator and [size=99px]==[/size] (double equals sign) is the COMPARISON operator.

So your code
if ($blocks = theme_blocks(“left”)) {
$output .= "


$output .= "

would be INCORRECT as a comparison operation. The condition (generally) would always be true because it evaluates that the assignment has happened successfully.

Also, because you broke up your code, it’s difficult to discern the actual construction of your IF statement.

Typically you will not go wrong with

if (conditional evaluation) {
   Do this Code ;
} else {
   Do this code instead;

I would like to note the use of the curly braces… Although they are not needed if the only statement to be executed (conditionally) is the very next statement (ONLY), however, I find that for ease of reading and for consistency, that I prefer to put them in there.

Sponsor our Newsletter | Privacy Policy | Terms of Service