使用php变量和css根据事件和sql数据更改背景颜色


Using php variables and css to change the background color based on events and sql data

希望这有意义,我希望能画出一幅清晰的画面。

<?php $rx_event_color = $rx_image_color = '#FF0000';
if ($a['rx_event_exists'] == 1) { $rx_event_color = '#00FF00'; }
if ($a['rx_scanned'] == 1) { $rx_image_color = '#00FF00'; }
else if ($a['rx_scanned'] > 1) { $rx_image_color = '#FFFF00'; }
?>

我不希望整个背景td改变颜色,只希望td内部的文本基于事件(sql中的数据)

if ($a['rx_event_exists'] == 0)
    {
    echo "<tr><td style='background:$rx_event_color'><a href='" 
                    . matry::here_to('new', array('tfilt'=>'WR', 'pfilt'=>$patient->code))
                    . "'>**Rx Event Not Created**</a></td></tr>";
    }

我试着把背景改成颜色,还试着把它添加到div中。。。我想这应该比原来更容易…这就是我在这里问的原因。提前感谢我的朋友们。

您需要将style属性移动到锚点标记,因为链接的样式控制的是文本的颜色,而不是td。根据您的用途,颜色和背景色可以在此处互换使用。

<td><a href='...' style='color:$rx_event_color'>...</a></td>

或者,您可以使用类:

.notfound a { color: red }
<td class="notfound"><a href="...">...</a></td>