1

In Mysql Table, I've a table name: mental_illness that there's two enum row inside as :

N and P

It means Negative and Positive

and here's my PHP code to retrieve data from that table:

  if ($history->getMentalIllness())
  {
    echo HTML::section(3, _("Mental Illness : "));
    echo HTML::para(nl2br($history->getMentalIllness()));
  }

Here's my question:

How to use if else in that above PHP code like this:

If Mental Illness is P, then show Positive text and If Mental Illness is N then show Negative text

Because this code just show P and N instead of Negative and Positive text.

Thank you

Alexander Richard
  • 191
  • 3
  • 8
  • 18

1 Answers1

0

Just do:

if ($history->getMentalIllness())
{
  echo HTML::section(3, _("Mental Illness : "));
  if($history->getMentalIllness() == 'P'){
    $mental_illness = "Positive";
  }else{
    $mental_illness = "Negative";
  }
  echo HTML::para(nl2br($mental_illness));
}

One more thing... Why would you need nl2br in this case... There are no newlines in these two strings...

  • Thank you so much, Its working like charm. for nl2br i'm using for all codes in view page, It shouldn't be any problem for this. anyhow thanks for your advice. Merci :) – Alexander Richard Nov 01 '15 at 15:57