我有下面的代码,我想添加一个元素到我的if语句中,但我不确定如何处理这个问题。我期望做的是在它的其他部分添加背景颜色。在此:在php if语句中为元素添加背景颜色
else {
$status_img = '<img src="../icons/collection/checkmark.png" alt="Goal Complete">';
}
所以,如果$status
不为0,我想设置背景颜色类goal-box-right
。
有反正我可以通过PHP来操纵CSS吗?
foreach ($rows as $row) {
$status = $row['status'];
if ($status == 0) {
$status_img = '<img src="../icons/collection/x-sign.png" alt="Goal Not Complete">';
}
else {
$status_img = '<img src="../icons/collection/checkmark.png" alt="Goal Complete">';
}
$goal_date = $row['date'];
$fixed_goal_date = fixDate($goal_date);
$html = "";
$html .= '<div class="goal-box" id="comment-'.$row['id'].'">';
$html .= '<div class="goal-box-left">'; //added
$html .= '<div class="goal-post-status">'.$status_img. '</div>';
$html .= '</div>'; //added
$html .= '<div class="goal-box-right">'; //added
$html .= '<div class="goal-post-title">'.$row['title']. '</div>';
$html .= '<div class="goal-post-date">'.$fixed_goal_date. '</div>';
$html .= '<div class="goal-post-description">'.$row['description']. '</div>';
$html .= '</div>'; //added
$html .= '</div>';
什么问题呢? –
为什么不将背景色设置为内联样式? – connexo
问题是我不知道如何通过我的if语句将背景颜色设置为不同的颜色。 – Paul