Help with some PHP syntax

I need some help. I’m very new to PHP programming (still learning) and I’ve written three separate snippets of code that I think should work, but don’t seem to work right. I’m including them below, with a short description of what I’m trying to accomplish with each snippet. Let me know if you see anything that’s “off” or not working, because in its current form, the code doesn’t seem to be working (it causes the page to stop loading). I think my syntax may be off.

-------ADJUST A COLUMN’S TITLE DEPENDING ON VARIABLE DATA--------

[php] <?php
if(empty($property[acres]))
echo ‘Size (min/max)’

    else
    	echo 'Acres'
    	?>

[/php]

--------Display property sq. ft. min/max if “acres” is empty, otherwise display property acres---------

[php] <?php

    if(empty($property[acres])) {
        echo $property[sq_ft_min]. " / " .$property[sq_ft_max];
    } 
    else {
    	echo $property[acres];
    }	
    	?>[/php]

--------If “price per sq. ft.” is empty, display “price”; otherwise, if “price” is empty, display the “price per sq. ft.”; otherwise, if both fields have data in them, display both fields----------

[php]<?php

if(empty($property[price_per_sq_ft])) {
echo $property[price];
}

elseif(empty($property[price])) {
echo $property[price_per_sq_ft];
}

else {
echo $property[price]. " / " .$property[price_per_sq_ft];
}
endif;

?>
[/php]

The first one looks fine, although I always think it’s a good idea to use brackets:

[php]if(empty($property[acres])) {
echo ‘Size (min/max)’;
} else {
echo ‘Acres’;
}[/php]

The second also looks fine. The third has an endif, which is not needed:

[php]if(empty($property[price_per_sq_ft])) {
echo $property[price];
} else if(empty($property[price])) {
echo $property[price_per_sq_ft];
} else {
echo $property[price]. " / " .$property[price_per_sq_ft];
}[/php]

Try that :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service