如果time2大於時間1,我希望背景顏色更改爲紅色。 我是一個完全noob在這和我現在試了幾天,但沒有得到它的工作。 在CSS我有.bgred {background: red;}
用PHP中的if語句更改backgroundcolor
<?php
$sql = ("SELECT name, time1, time2 FROM myTable WHERE dates LIKE '".$_POST['dat']."' ");
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
echo "<table action='' method='POST'><tr>
<th>Name</th>
<th>Time1</th>
<th>Time2</th></tr>";
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
$var1 = $row["time1"];
$var2 = $row["time2"];
if($var2 < $var1) {
$bgred = 'class="bgred"';
} else {
$bgred = '';
}
echo "<tr><td>".$row["name"]."</td>
<td>".$row["time1"]."</td>
<td class="$bgred">".$row["time2"]."</td></tr>";
}
}
echo "</table>";
mysqli_close($conn);
?>
http://stackoverflow.com/a/39444025/3558278 – Deep