当我在表格中列出PHP结果时,如何在数据更改时更改border-bottom-color?

功能性嬉皮

在我的网站上,我将返回带有检查日期的房屋检查项目列表。我每天要进行几次检查,并按“ datetimeinspection”进行排序。当我的表格显示出来时,我希望在每天的最后一次检查中增加线宽或使用其他线条颜色。

我很清楚根据每行的数据更改属性。例如,在下面的示例代码中,我离开了使用“状态”列的数据设置每一行颜色的部分。我在这里面临的挑战是比较各行之间的数据,以了解在哪里更改边界底端。

<table>
    <tr style="height:30px; border: 1px solid #CCCCCC;">
        <td>Job Number</td>
        <td>Insured Name</td>
        <td>Address</td>
        <td>City</td>
        <td>County</strong></td>
        <td>Inpection Scope</strong></td>
        <td>Date of Loss</strong></td>
        <td>Inspection Date</strong></td>
    </tr>
    <? while ($row = mysqli_fetch_assoc($result1)) {
        if ($row['status'] == "Scheduled") { ?>
            <tr style="color: #16B148; ">
        <? } elseif ($row['status'] == "Closed") { ?>
            <tr style="color: #CDD4D7; text-decoration:line-through">
        <? } elseif ($row['status'] == "Inspected") { ?>
            <tr style="background-color: #92D050 ">
        <? } elseif ($row['status'] == "Delay by NI") { ?>
            <tr style="color: #9D16B1 ">
        <? } elseif ($row['status'] == "Delay by rep") { ?>
            <tr style="color: #9D16B1 ">
        <? } elseif ($row['status'] == "Tentative") { ?>
            <tr style="color: green ">
        <? } elseif ($row['status'] == "New") { ?>
            <tr style="color: red; font-weight: 250 ">
        <? } elseif ($row['status'] == "Left Voicemail") { ?>
            <tr style="color: #92D050 ">
        <? } ?>
        <td><? echo $row["claimnumber"] ?></td>
        <td><? echo $row["insuredname"] ?></td>
        <td><? echo $row["insuredaddress"] ?></td>
        <td><? echo $row["insuredcity"] ?></td>
        <td><? echo $row["insuredcounty"] ?></td>
        <td><? echo $row["inspectionscope"] ?></td>
        <td><? echo $row["dateofloss"] ?></td>
        <td><? echo $row["datetimeinspection"] ?></td>
        </tr>
    <? } ?>
</table>
会计م

这是关于样本数据的想法

<?php

//15 rows
$dates = [
'2019-08-19 00:00:00',
'2019-08-20 00:00:00',
'2019-08-21 00:00:00',
'2019-08-21 00:00:00',
'2019-08-21 00:00:00',
'2019-08-22 00:00:00',
'2019-08-22 00:00:00',
'2019-08-22 00:00:00',
'2019-08-23 00:00:00',
'2019-08-23 00:00:00',
'2019-08-23 00:00:00',
'2019-08-24 00:00:00',
'2019-08-24 00:00:00',
'2019-08-25 00:00:00',
'2019-08-25 00:00:00',
];

$lastDay = "";
$i = -1;
foreach ($dates as $date){
    $i++;
    $dateTime = new DateTime($date);
    if ($lastDay != $dateTime->format("d") && $i != 0){
        echo ($i - 1) . " is a last row in a day\n";
    }
    $lastDay = $dateTime->format("d");
}

echo $i . " is a last row in a day\n";; // last row must be a last row in a day also

这个输出

0 is a last row in a day
1 is a last row in a day 
4 is a last row in a day 
7 is a last row in a day 
10 is a last row in a day 
12 is a last row in a day 
14 is a last row in a day

现场演示(https://3v4l.org/jc0BY

要将其应用于您的代码示例,您可以执行以下操作

<?php

$rows = [];
$lastDay = "";
$i = -1;
while ($row = mysqli_fetch_assoc($result1)){
    $i++;
    $dateTime = new DateTime($row['datetimeinspection']);
    $rows[] = $row;
    if ($lastDay != $dateTime->format("d") && $i != 0){
        $rows[$i - 1]['lastRowInDay'] = true;
    }
    $lastDay = $dateTime->format("d");
}
$rows[$i]['lastRowInDay'] = true;

foreach ($rows as $row){
    if (!empty ($row['lastRowInDay'])){
        //this is the last row in the day , give it the CSS that you want
         echo '<tr style="border-bottom:2px solid red">';
    } else if ($row['status'] == "Scheduled"){
        echo '<tr style="color: #16B148; ">';
    } else if ($row['status'] == "Closed"){
        echo '<tr style="color: #CDD4D7; text-decoration:line-through">';
    } else if ($row['status'] == "Inspected"){
        echo '<tr style="color: #92D050; ">';
    } else if ($row['status'] == "Delay by NI"){
        echo '<tr style="color: #9D16B1; ">';
    } else if ($row['status'] == "Tentative"){
        echo '<tr style="color: #green; ">';
    } else if ($row['status'] == "New"){
        echo '<tr style="color: red; font-weight: 250">';
    } else if ($row['status'] == "Left Voicemail"){
        echo '<tr style="color: #92D050;">';
    }
    echo '<td>' . htmlspecialchars($row["insuredname"]) . '</td>';
    echo '<td>' . htmlspecialchars($row["insuredcity"]) . '</td>';
    echo '<td>' . htmlspecialchars($row["insuredcounty"]) . '</td>';
    echo '<td>' . htmlspecialchars($row["inspectionscope"]) . '</td>';
    echo '<td>' . htmlspecialchars($row["dateofloss"]) . '</td>';
    echo '<td>' . htmlspecialchars($row["datetimeinspection"]) . '</td>';
    echo '<td>' . htmlspecialchars($row["insuredname"]) . '</td>';
    echo '</tr>'

}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

为什么当border-bottom-style等于'none'时指定border-bottom-color?

如何让tr border-bottom-bottom而不是td

不同浏览器中的“ Border-Bottom-Bottom”面板

devtools中的bottom-bottom是什么意思?

如何忽略CSS bottom属性?

如何在应用程序中更改@color

如何在vuetify中更改v-data-table标头的backkground-color和border-radius?

不确定如何在CSS中使用border-bottom

我如何创建这个 Curved Bottom ImageView?

当鼠标悬停时,CSS border-bottom-bottom应该扩展

防止HTML / CSS-Navbar在使用border-bottom-bottom时改变高度

填充前的css border-bottom

Border Radius Bottom Bug React Native

绝对列未显示border-bottom

在tr标签下添加border-bottom

AngularJS:当css类更改时,如何通过切换更改color属性?

如何比较Color对象并获取Color []中最接近的Color?

如何设置 color.Color 值?

在Firefox中,margin-top / bottom%无效

ngx-color-picker在输入更改时被关闭

如何根据SQL数据库更改btn-color

单击从pub dev获得的flutter_bottom_bar 1.2.0时如何更改屏幕

如何添加动画以更改SNCNode的Color SceneKit?

在链接悬停时在CSS过渡上应用border-bottom

ol.style.stroke中的不同颜色border-bottom

为什么在使用react和antd时不能将margin-bottom-bottom重置为0?

Android Studio-更改NOT OF BOTTOM NAVIGATION VIEW的颜色

将view.bottom限制为superview.bottom而不是情节提要中的bottomLayoutGuide

如何在bootstrap-select中更改background-color选项?