fatch db data和match date with today,如果lastdate过期则为red

时间:2018-03-07 07:41:25

标签: php date

有人可以帮忙吗?

  1. 如果行lastdate单元已经过期,如何在行上添加颜色?

  2. 另外,我如何按格式(日 - 月 - 年)按降序排列日期?

  3. 这是我的代码:

    <?php
    
    include('connect-mysql.php');
    
    $sqlget = "SELECT * FROM job ORDER BY id DESC";
    $sqldata = mysqli_query($dbcon, $sqlget) or die('error getting data');
    
    
    
    echo "<table>";
    echo "<tr><td><b>ID</b></td><td><b>Description</b></td><td><b>Source</b><td><b>Fee</b><td><b>Last Date</b></td><td><b>Details</b></td></tr>";
    $serial = 1;
    while($row = mysqli_fetch_array($sqldata, MYSQLI_ASSOC)) {
        echo "<tr><td>";
        echo $serial;
        echo "</td><td>";
        echo $row['desc'];
        echo "</td><td>";
        echo $row['src'];
        echo "</td><td>";
        echo $row['fee'];
        echo "</td><td>";
        echo $row['lastdate'];
        echo "</td><td>";
        echo "<center><div  class='view'><a href='details.php?id={$row['id']}'>";
        echo "View";
        echo "</a></div></center></td></tr>";
        $serial++; //increment Serial Number by 1 on every pass 
    } 
    
    echo "</table>";
    
    ?>
    

    由于

1 个答案:

答案 0 :(得分:0)

试试这个:)

- 表test

的表结构
DROP TABLE IF EXISTS `test`;
CREATE TABLE IF NOT EXISTS `test` (`id` int(11) NOT NULL AUTO_INCREMENT,
`lastdate` varchar(50) DEFAULT NULL,PRIMARY KEY (`id`)) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=latin1;

-

- 转储表test

的数据
INSERT INTO `test` (`id`, `lastdate`) VALUES
(1, '10-03-2018'),
(2, '08-03-2018'),
(3, '07-03-2018'),
(4, '06-03-2018'),
(5, '11-03-2018');

<?php
include('connect.php');
$sqlget = "SELECT * FROM test ORDER BY lastdate DESC";
$sqldata = mysqli_query($dbcon, $sqlget) or die('error getting data');

echo "<table border='2' cellpadding='5' cellspacing='5'>";
echo "<tr><td>Last Date</td></tr>";

while($row = mysqli_fetch_array($sqldata, MYSQLI_ASSOC)) {
$lastdate=$row['lastdate'];
$todays_date = date("d-m-Y");

$today=strtotime($todays_date);
$exp_date=strtotime($lastdate);

echo "<tr>";
echo "<td>";
if($exp_date < $today){
echo "<font color='red'>"."<strong>".$row['lastdate']."</strong>"."</font>";
}
else{
echo $row['lastdate'];; 
}
echo "</td>";
echo "</tr>";
} 

echo "</table>";