Hi all,
I am displaying a table of data using the CGridView widget and I have got a column that is combing the data from several database fields and displaying them in the one column. This is used to display a full address where in the database they are entered as line 1, line 2, town, postcode etc.
I have managed to get the combined fields working and I am separating each field with a comma but I have found that many of the fields are empty and so on some records I just get the commas. For example:
Record 1 - Line1, Line2, Town, Postcode
Record 2 - Line1, Town, Postcode
Record 3 - , Postcode
My code for this is as follows:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'properties-grid',
'dataProvider'=>$dataProvider,
'columns'=>array(
'pr_id',
array(
'name'=>'Address',
'value'=>'$data->pr_location_line1 . ", " . $data->pr_location_line2 . ", " . $data->pr_location_line3 . ", " . $data->pr_location_line4 . ", " . $data->pr_location_line5 . ", " . $data->pr_location_post_town . ", " . $data->pr_location_postcode',
),
'pr_status',
'pr_updated',
'pr_administrator',
'pr_updated',
array(
'class'=>'CButtonColumn',
),
),
)); ?>
Ideally what I would like is some way of checking that if the field is empty (or null) then the comma is not displayed. I have tried a few if statements but they don’t work.
Does anyone know how this can be achieved?
I am looking to display the records as demonstrated above as:
Record 1 - Line1, Line2, Town, Postcode
Record 2 - Line1, Town, Postcode
Record 3 - Postcode
Many thanks