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

  • 写回答

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集