1

ステータスが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>"; 
4

3 に答える 3

2

基本的に同じ種類の三項演算を実行します。

($ins_event['status'] == 2 ? ' style="color: ' . $rx_ev_status . '"' : '')
于 2013-02-13T00:15:49.140 に答える
1

これはどういう意味ですか?あなたの質問はそれほど明確ではありません。

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

これは、わかりやすくするためにエコーを別の行に分割した編集です...

echo '<tr><td>&nbsp;<img src="/check-icon.gif">';
echo '<a '.($ins_event['status'] == 2 ? 'style="color:'.$rx_ev_status.';"': '')." ";
echo ' href="'. matry::here(array('event_id'=>$ins_event['id'])) . '">'; 
echo ($ins_event['status'] == 2 ? 'Completed Insurance Event': 'Active Insurance Event');
echo '</a></td></tr>'; 
于 2013-02-13T00:14:35.737 に答える
-2

はい。パフォーマンスとコードのメンテナンス上の理由から、ロジック操作はできるだけ頻繁に実行しないでください。if { … } else { … }1つのブロック内にテキストステータスとカラー変数の両方を設定します。echoステータスと色を変数に保存した後、ステートメントを大幅に簡略化できます。

echo "<tr><td>&nbsp;<img src='/check-icon.gif'> <a href='". matry::here(array('event_id'=>$ins_event['id'])) . "'>$status</a></td></tr>";

matry::here(…)また、コードをさらに読みやすくするために、の出力を変数に格納することも検討します。

于 2013-02-13T00:16:30.387 に答える