gpt4 book ai didi

php - 更改TD的背景颜色

转载 作者:太空宇宙 更新时间:2023-11-04 13:37:21 25 4
gpt4 key购买 nike

如果一个值大于另一个,我想更改其中一行的背景颜色。

我尝试使用 jQuery 更改颜色,但它会更改每一行的颜色。

这是我的代码:

while ($row = mysqli_fetch_assoc($result)) {

echo'<tr>';
echo'<td>'.$row['id'].'</td>';
echo'<td style="width:25%"><a href="calendarevent.php? EventId='.urlencode($row['id']).'">'.$row['date'].'</a></td>';
echo'<td class="starttime">'.$row['start'].'</td>';
echo'<td class="finishtime">'.$row['finish'].'</td>';
echo'<td>'.$row['total'].'</td>';
echo'<td>'.$row['cash'].'</td>';
echo'</tr>';

$start =$row['start'];
$finish = $row['finish'];
if ( $start<$finish ) {
//CHANGE BACK GROUND COLOR FOR finish time to red
}else{
//Keep the color as it was
}

}

最佳答案

在渲染 TD 之前测试该值,然后将特定类添加到 TD,然后使用该类为 TD 设置样式

<style type="text/css">
.redCell {
background-color: red;
}
</style>

<?php

// Loop Through DB Rows
while ($row = mysqli_fetch_assoc($result)) {
echo'<tr>';
echo'<td>'.$row['id'].'</td>';
echo'<td style="width:25%"><a href="calendarevent.php? EventId='.urlencode($row['id']).'">'.$row['date'].'</a></td>';
$start =$row['start'];
$finish = $row['finish'];

// Test the value
if ( $start<$finish ) {
$class = "redCell"; // Add a new class to make it red
}else{
$class = ""; // Keep the color as it was
}

echo'<td class="starttime">'.$row['start'].'</td>';

// Add the style to the TD
echo'<td class="finishtime '.$class.'">'.$row['finish'].'</td>';
echo'<td>'.$row['total'].'</td>';
echo'<td>'.$row['cash'].'</td>';
echo'</tr>';
}
?>

关于php - 更改TD的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22947212/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com