回显布尔字段为是/否或其他值 [英] Echo boolean field as yes/no or other values

查看:64
本文介绍了回显布尔字段为是/否或其他值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在只读S​​QL表上有一个名为 attended 的字段,该字段只能容纳两个0或1值.

I have a field on a read only SQL table called attended can only hold two values either 0 or 1.

这是我目前打印字段的方式:

This is how I am printing the field at the moment:

  echo "<td>" . $row['attended'] . "</td>";

它仅返回0或1-有人照管的字段中的值.如何获得 0(即未参加)或1 (即参加)

It only returns 0 or 1 - the value in the attended field. How can I have it return no for 0 (i.e not attended) or yes for 1 (i.e. attended).

非常感谢!

推荐答案

您可以使用三元运算符(在某些语言中也称为条件运算符)?::

You can use the ternary operator (also known as the conditional operator in some languages) ?::

echo '<td>' . ($row['attended'] ? 'yes' : 'no') . '</td>';

在手册页比较运算符中的三元运算符"标题下提到了该运算符

This operator is mentioned in the manual page Comparison Operators under the heading "Ternary Operator".

这篇关于回显布尔字段为是/否或其他值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆