Here is my code,
if ($_SESSION["crossfit"]=="Y") { if ($_SESSION["tr_duration1"]==1) { $dr1="1 Month"; } else {
if ($_SESSION["tr_duration1"]==12) { $dr1="1 Year"; } else
{ $dr1=$_SESSION["tr_duration1"] . ' Months'; }} $c1='Crossfit - ' . $dr1;}
if ($_SESSION["muaythai"]=="Y") { if ($_SESSION["tr_duration2"]==1) { $dr2="1 Month"; } else {
if ($_SESSION["tr_duration2"]==12) { $dr2="1 Year"; } else
{ $dr2=$_SESSION["tr_duration2"] . ' Months'; }} $c2=', Muaythai - ' . $dr2;}
if ($_SESSION["mma"]=="Y") { if ($_SESSION["tr_duration3"]==1) { $dr3="1 Month"; } else {
if ($_SESSION["tr_duration1"]==12) { $dr3="1 Year"; } else
{ $dr3=$_SESSION["tr_duration3"] . ' Months'; }} $c3=', MMA - ' . $dr3;}
if ($_SESSION["gymnastics"]=="Y") { if ($_SESSION["tr_duration4"]==1) { $dr4="1 Month"; } else {
if ($_SESSION["tr_duration4"]==12) { $dr4="1 Year"; } else
{ $dr4=$_SESSION["tr_duration4"] . ' Months'; }} $c4=', Gymnastics - ' . $dr4;}
$for = $c1 . $c2 . $c3 . $c4 . '.';
At least one of the programs will be 'Y' or all of them.
What I want is that $c1 $c2 $c3 $c4 come out separated by ',' and ends with '.' so it becomes readable.
My problem is if I put
$for = $c1 . $c2 . $c3 . $c4 . '.'; and the ',' with $c1 and select programs 2 and 3
I get
$for = , Muaythai - 3 Months, MMA - 12 Months.
of course I want,
$for = Muaythai - 3 Months, MMA - 12 Months.
If I put ',' in the $for directly and remove from $c1 if 2nd and 3rd programs are selected
$for = $c1 . ',' . $c2 . ',' . $c3 . ',' . $c4 . '.'
I get
$for = ,Muaythai - 3 Months, MMA - 12 Months,.
I want
$for = Muaythai - 3 Months, MMA - 12 Months.
I have also tried putting nesting so many isset's but haven't succeeded. I have also tried by making a 'for' loop but ended up with more syntax errors than output errors
It works fine only if I select only the first program or all the 4 programs.