I'm struggling with this IF statement. I'm trying to make any cell that is older than today turn red, but all the cells are turning red. I'm sure it's an obvious mistake but I can't see the wood for the trees.
The IF statement at line 59 is the one I am having issues with. I want the option for checking the date on all columns but am trailing with "Not Started" first.
Any help would be appreciated.
$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>
Aucun commentaire:
Enregistrer un commentaire