早上好,我已经为用PHP和Javascript编写的工作编写了一个Dashboard。它从我们的数据库中提取数据,并用Dash类显示Div中的事件,显示$nextupdate的变量,我需要写一些Js来比较DateTimeNow,如果$nextupdate变量时间已经过去,那么我需要将Div类更改为逾期,我正在努力想办法解决这个的最佳方法
如有任何帮助,将不胜感激
问候
Steve
试试这个:
$nextupdate; // got from the database
$now = date();
$divClass = "";
if(strtotime($now) > strtotime($nextupdate) ){
$divClass="overdue";
}else{
$divClass="whatever";
}
然后:
<div class="<?php echo $divClass; ?>"></div>
这非常适合在过期时将div颜色更改为红色,尽管我没有解释我有多个div。。。
这是我的Div 代码
//Gather all Posted HPi tickets raised
$sql = "Select *
From hpi_calls
where status!='Closed'
and (Priority='P1' or Priority='M1')
order by NextUpdate Asc";
$result = $conn->query($sql);
$statuslist = "";
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$SR = $row["SR"];
$Priority = $row["Priority"];
$Customer = $row["Customer"];
$BDescription = $row["BDescription"];
$Team = $row["Team"];
$Engineer = $row["Engineer"];
$OpenTime = $row["OpenTime"];
$Status = $row["Status"];
$LastUpdate = $row["LastUpdate"];
$NextUpdate = $row["NextUpdate"];
$Owner = $row["Owner"];
$FDescription = $row["FDescription"];
$ASites = $row["ASites"];
$LoggingTeam = $row["LoggingTeam"];
$OwningTeam = $row["OwningTeam"];
$FUpdate = $row["FUpdate"];
$Supplier = $row["Supplier"];
$NextUpdate;
$now = date("Y-m-d H:i");
$divClass = "";
if(strtotime($now) > strtotime($NextUpdate) ){
$divClass="Overdue";
}else{
$divClass="Dash";
}
$statuslist .= '<div id="status_'.$SR.'" class=" '.$divClass.'"><h2>'
.$SR.'</h2><h2>'.$Customer.'</h2><h2>'.$Priority.'</h2> - '.$Status.'<br><h2>Next Update Due:<br>'.$NextUpdate.'</h2></div>';
}
}
以上是从DB中选择并发布到Divs 的完整代码
问候
Steve