php - 在 php 中使用三元运算符根据 sql 中的事件状态回显不同的状态

标签 php html sql css

好吧,如果状态为 1,则为“有效保险事件”,如果为 2,则为“已完成保险事件”。

if(!empty($ins_event))
            {
            echo "<tr><td>&nbsp;<img src='/check-icon.gif'> <a href='". matry::here(array('event_id'=>$ins_event['id'])) . "'>" . ( $ins_event['status'] == 2 ? "Completed Insurance Event": "Active Insurance Event") . "</a></td></tr>"; 
            }
else 
        {
        echo "<tr><td>" . cbox_return() . "<a href='". matry::here_to('new', array('tfilt'=>'IN', 'pfilt'=>$patient->code)) . "' style='color: #000; color:$rx_image_color'>**Ins Event Not Created**</td></tr>";
        }

我这里有一个颜色变量:

<?php
$rx_event_colors = $rx_ev_status = '#009933';
?>

我如何使用这个变量来获取 2 的状态并更改字体颜色。

我应该分解脚本并使用 if {} else {} 语句吗?


更新代码:

echo "<tr><td>&nbsp;<img src='/check-icon.gif'> <a href='". matry::here(array('event_id'=>$ins_event['id'])) . "'" . ( $ins_event['status'] == 2 ? ' style="color: ' . $rx_ev_status . '">Completed Insurance Event' : '>Active Insurance Event') . "</a></td></tr>"; 

最佳答案

你基本上会做同样的三元运算:

($ins_event['status'] == 2 ? ' style="color: ' . $rx_ev_status . '"' : '')

关于php - 在 php 中使用三元运算符根据 sql 中的事件状态回显不同的状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14844292/

相关文章:

php - 如何从事件的View Laravel生成PDF

php - 删除在 php/mysql 中不起作用的查询?

html - 图像不粘在页面底部

html - Angular html 无法正确加载

javascript - 阻止 Chrome 提示从输入框保存密码?

sql - 转换另一个表 Postgres 中的 int[] 元素中的 id

php - Mysql 第二次 JOIN 返回空数组

javascript - 下拉菜单需要转到提交时分配的值

c# - 实体之间的一对一关系不适用于 Entity Framework 6

java - 从 jdbc ResultSet 获取数据行