我正在努力解决这个IF声明。我试图让任何比今天更老的细胞变成红色,但所有细胞都变红了。我确定这是一个明显的错误,但我看不到树木的木材。
第59行的IF声明是我遇到的问题。我想要选项来检查所有列上的日期,但结尾为"未开始"第一
任何帮助都将不胜感激。
$notstarted = array();
$intransit = array();
$awaiting = array();
$built = array();
$cfc2 = array();
$received = array();
$date_created = array();
$date = date('Y-m-d');
try {
//open the PDO-connection to a MySQL-host
$DBH = new PDO("mysql:host=$host;dbname=$daba", $user, $pass);
//error mode set to EXCEPTION (ERRMODE_SILENT or ERRMODE_WARNING are also possible)
$DBH->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
//execute the query
$STH = $DBH->query('SELECT status, ticket, site, date_created FROM stores ORDER BY ticket');
//set default fetch mode to FETCH_ASSOC (if you want to try FETCH_OBJ)
$STH->setFetchMode(PDO::FETCH_ASSOC);
}
catch(PDOException $e) {
echo $e->getMessage();
}
//go through all results and assign them to the related arrays
while($row = $STH->fetch()) {
$data = $row['ticket'] . ' (' . $row['site'] . ')';
if ($row['status'] == "Not Started") { $notstarted[] = $data; }
if ($row['status'] == "In Transit") { $intransit[] = $data; }
if ($row['status'] == "Awaiting Build") { $awaiting[] = $data; }
if ($row['status'] == "Being Built") { $built[] = $data; }
if ($row['status'] == "On Return from CFC2") { $cfc2[] = $data; }
if ($row['status'] == "Received") { $received[] = $data; }
}
//close the connection
$DBH = null;
?>
<table align="center" border="1" width="90%">
<tr>
<td align="center" bgcolor="#FDFEAD"><font face="Arial"><strong>Not Started</strong></font></td>
<td align="center" bgcolor="#FDFEAD"><font face="Arial"><strong>In Transit</strong></font></td>
<td align="center" bgcolor="#FDFEAD"><font face="Arial"><strong>Awaiting Build</strong></font></td>
<td align="center" bgcolor="#FDFEAD"><font face="Arial"><strong>Being Built</strong></font></td>
<td align="center" bgcolor="#FDFEAD"><font face="Arial"><strong>On Return</strong></font></td>
<td align="center" bgcolor="#FDFEAD"><font face="Arial"><strong>Received Back</strong></font></td>
</tr>
<?php
for ($i = 0; $i < max(count($notstarted),count($intransit),count($awaiting),count($built),count($cfc2),count($received)); $i++) {
echo "<tr>";
if (count($notstarted) > $i) {
if ($row['date_created'] <= $date) {
echo "<td align=\"center\" bgcolor=\"red\"><font face=\"Arial\">";
} else {
echo "<td align=\"center\" bgcolor=\"#BCBBBB\"><font face=\"Arial\">";
}
echo $notstarted[$i];
echo "</font></td>";
}
echo "<td align=\"center\"><font face=\"Arial\">";
if (count($intransit) > $i) echo $intransit[$i];
echo "</font></td>";
echo "<td align=\"center\"><font face=\"Arial\">";
if (count($awaiting) > $i) echo $awaiting[$i];
echo "</font></td>";
echo "<td align=\"center\"><font face=\"Arial\">";
if (count($built) > $i) echo $built[$i];
echo "</font></td>";
echo "<td align=\"center\"><font face=\"Arial\">";
if (count($cfc2) > $i) echo $cfc2[$i];
echo "</font></td>";
echo "<td align=\"center\" bgcolor=\"#95FA95\"><font face=\"Arial\">";
if (count($received) > $i) echo $received[$i];
echo "</font></td>";
echo "</tr>";
}
?>
</table>
答案 0 :(得分:1)
不要将日期与<
(小于)运算符进行比较。
if(strtotime($row['date_created']) <= time()) {
red logic
} else {
non-red logic
}
您可能需要阅读strtotime。
您的代码还有许多其他问题需要清理,首先是缩进。由于缩进,您的代码中存在问题的部分非常难以处理。