dougan7523
2015-11-01 14:33
浏览 19
已采纳

如何在mysql表列中检索数据?

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

图片转代码服务由CSDN问答提供 功能建议

在Mysql Table中,我有一个表名: mental_illness 表示有两个枚举行 内部为:

N P

这意味着消极和积极

这是我从该表中检索数据的PHP代码:

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

这是我的问题

如何在上面的PHP代码中使用if else:

如果精神疾病 P ,则显示正面文字 如果精神疾病为< strong> N 然后显示否定文字

因为此代码只显示 P N 而不是否定和 正文。

谢谢

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doupu1957 2015-11-01 15:39
    已采纳

    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...

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题