Welcome Guest, Not a member yet? Register   Sign In
Ternary usage
#1

[eluser]Todlerone[/eluser]
Hello everyone and TY in advance. I'm trying to use a ternary condition to establish some output in a view. However, I keep getting errors. I have three possible prefixes to a word. What I'm trying to do is determine if each one is set in the database then append them together with a space between them. Example: Lt Sup Occipital or Lt Ant Occipital.

My variables are sagittal, axial or coronal. Here is a sample of what I have tried in my view.

Code:
<?php $location = ($plan['sagittal']) ? $plan['sagittal']." " : //nothing ?>
<?php $location .= ($plan['axial']) ? $plan['axial']." " : //nothing ?>
<?php $location .= ($plan['coronal']) ? $plan['coronal']." " : //nothing ?>
....then echo out $location

TY for any help
#2

[eluser]Johan André[/eluser]
try ''; after the :
#3

[eluser]cideveloper[/eluser]
I think you have to put the else statement after the ":"


Code:
<?php
$location = ($plan['sagittal']) ? $plan['sagittal']." " : "";
$location .= ($plan['axial']) ? $plan['axial']." " : "";
$location .= ($plan['coronal']) ? $plan['coronal']." " : "";
?>




Theme © iAndrew 2016 - Forum software by © MyBB