如何在PHP中向if-else语句添加CSS

如何在PHP中向if-else语句添加CSS,php,css,Php,Css,我想根据接受(绿色)或拒绝(红色)更改状态文本的颜色。目前,它们给出的值为“1”被接受或“2”被拒绝 我如何根据结果改变颜色 以下是我的PHP: $query = "SELECT * FROM `REQUESTS` ORDER BY $selectOption"; echo $query; $result = $db->query($query); if ($result == FALSE){ die ("could not execute statement $query&l

我想根据接受(绿色)或拒绝(红色)更改状态文本的颜色。目前,它们给出的值为“1”被接受或“2”被拒绝

我如何根据结果改变颜色

以下是我的PHP:

$query = "SELECT * FROM `REQUESTS` ORDER BY $selectOption"; 
echo $query;
$result = $db->query($query);
if ($result == FALSE){ 
    die ("could not execute statement $query<br />");
} else {
    echo "<form action='' method='post'>";
    echo "<table>";                         
    while($row=$result->fetchRow()){                        
        echo "<td>" . $row['status'] . "</td>";
    }
    echo "</tr>";
    echo "</table>"; 
}
$query=“从`REQUESTS`中选择*orderby$selectOption”;
echo$query;
$result=$db->query($query);
如果($result==FALSE){
die(“无法执行语句$query
”; }否则{ 回声“; 回声“; 而($row=$result->fetchRow()){ 回显“$row['status']”; } 回声“; 回声“; }
更改此选项:

echo "<td>" . $row['status'] . "</td>";
echo”“$行['status']。"";
作者:

echo“$row['status']”;

使用设置创建两个div

在reject消息周围设置reject div,在accept div周围设置accept div

我不确定我是否理解这里的问题

编辑:


对不起,我现在明白状态是拒绝/接受。我以为它是$Result

你可以像这样在
中添加
样式
属性

$query = "SELECT * FROM `REQUESTS` ORDER BY $selectOption"; 
echo $query;
$result = $db->query($query);
if ($result == FALSE){ 
    die ("could not execute statement $query<br />");
} else {
    echo "<form action='' method='post'>";
    echo "<table>";                         
    while($row=$result->fetchRow()){

        $style = $row['status'] == 1 ? 'green' : 'red';
        echo "<td style='color:$style'>" . $row['status'] . "</td>";
    }
    echo "</tr>";
    echo "</table>"; 
}

您可以根据状态应用不同的css类

CSS:

td.status-accepted{color:green;}
td.status-rejected{color:red;}
$query = "SELECT * FROM `REQUESTS` ORDER BY $selectOption"; 
echo $query;
$result = $db->query($query);
if ($result == FALSE){ 
    die ("could not execute statement $query<br />");
} else {
    echo "<form action='' method='post'>";
    echo "<table>";                         
    while($row=$result->fetchRow()){                        
    echo '<td class="'.(($row['status'] == 2) ? 'status-rejected' : 'status-accepted'). '">'.$row['status'].'</td>';
    }
    echo "</tr>";
    echo "</table>"; 
}
HTML/PHP:

td.status-accepted{color:green;}
td.status-rejected{color:red;}
$query = "SELECT * FROM `REQUESTS` ORDER BY $selectOption"; 
echo $query;
$result = $db->query($query);
if ($result == FALSE){ 
    die ("could not execute statement $query<br />");
} else {
    echo "<form action='' method='post'>";
    echo "<table>";                         
    while($row=$result->fetchRow()){                        
    echo '<td class="'.(($row['status'] == 2) ? 'status-rejected' : 'status-accepted'). '">'.$row['status'].'</td>';
    }
    echo "</tr>";
    echo "</table>"; 
}
$query=“从`REQUESTS`中选择*orderby$selectOption”;
echo$query;
$result=$db->query($query);
如果($result==FALSE){
die(“无法执行语句$query
”; }否则{ 回声“; 回声“; 而($row=$result->fetchRow()){ 回显'.$row['status'].'; } 回声“; 回声“; }