我必须在表格中显示两种不同颜色,即创建日期等于或少于3天,单元格应为“#FFFF00”颜色。否则单元格应该是“#008000”,这是我的代码,
<?php if ($project->post_date) : ?>
<?php
$today_time = strtotime(date('m/d/y'));
$created_time = "<?php echo date('m/d/y', strtotime($project->post_date)-3) ?>";
if ($created_time == $today_time) {
$stylis = "style='color:#ffff00;'";
} else {
$stylis = "style='color:#008000'";
?>
<?php endif; ?>
答案 0 :(得分:0)
这是你的答案
<?php
if($project->post_date){
$today_time = date('m/d/y');// Change this
$created_time = date('m/d/y', strtotime($project->post_date .'-3 days'));
if ($created_time == $today_time) $stylis = "style='color:#ffff00;'";
else $stylis = "style='color:#008000'";
echo $stylis;
}
?>
答案 1 :(得分:0)
以下代码适合您:
if ($project->post_date) {
$today_time = strtotime('-3 day');
$created_time = date('m/d/y', strtotime($project->post_date));
echo $created_time. " - ".$today_time."<br>";
if (strtotime($created_time) > $today_time) {
$stylis = "style='color:#ffff00;'";
}
else
{
$stylis = "style='color:#008000'";
}
}
如果您需要任何进一步的帮助,请告知我们。
谢谢!