Need help with a line of php code please

Hi I am new to php but I’ve been building websites for about 15 years. I have a property sale site that is almost finished. Each property listing currently shows the area and city. I want to add the country too.

Here is the current code

location
                    <?php  
                    if ($property_area != '') {
                        echo $property_area.', ';
                    } 
                    echo $property_city;?>

                </div>

I cant add an attachment sorry of the screenshot. But basically at the moment a property location shows as

East Side, New York

and I want it to display

East Side, New York, USA

I’ve tried to add the php code myself for the comma and the property_country with no success. Please can anyone advise me? Thanks

Give this a try

[php]

location
                    <?php 
                    if ($property_area != '') {
                        echo $property_area.', ';
                    }
                    echo $property_city.', '.$property_country;

?>

                </div>

[/php]

Using positive logic you could do it this way -
[php]if ($property_area) {
echo $property_area . ', ‘;
}
echo $property_city.’, '.$property_country;[/php]

Correct either way, but for me I like using positive logic if at all possible. For me it easier to grasp the logic if something is true rather than is not true. In this case if it is not empty (or NULL) then perform if statement, but I rather think of it as if variable contains data then perform if statement.

Sponsor our Newsletter | Privacy Policy | Terms of Service