Insert a multi-line address

2 posts by 2 authors in: Forums > CMS Builder
Last Post: July 8, 2016   (RSS)

By Perchpole - July 7, 2016

Hello, All -

I'm trying to find a smart way to insert a multi-line address into a CMSB table. I'm using the standard $colsToValues approach which I've used many times - but it's all coming appart when it comes to the address.

I am trying to create a multi-line entry formed from several variables:

Address1
Address2
City
PostCode
Country

This works fine:

$colsToValues['address'] = $_SESSION['strAddress1']."\r\n".$_SESSION['strAddress2']."\r\n".$_SESSION['strCity'];

However, in practise, hardly anyone ever fills in Address2. This means that when the address appears in the DB it looks like this:

Address1

City
PostCode
Country

I want to get rid of the gap!

I've tried using a ternary operator - to exclude the line break when Address2 is not present - but it doesn't quite work as expected.

$colsToValues['address'] = $_SESSION['strAddress1']."\r\n".$_SESSION['strAddress2'].$_SESSION['strAddress2'] ? "\r\n" : ''.$_SESSION['strCity'];

Can someone please explain what I'm doing wrong?!

:0)

Perch