Een tabel met een registratie systeem, ook een veld met lastactive (datetime).
Ik doe bij mijn AdminCP een lijst met alle leden op de pagina printen en ook degene rood markeren die nog niet online zijn gekomen.
Wat ik nu ook nog wil is degenen markeren die al twee weken niet online zijn. Dit dacht ik op te lossen met datediff(), waarbij ik deze code nu heb:
<?php
$sql2 = mysql_query("SELECT DATEDIFF(CURDATE(), lastactive) AS dagen_offline FROM `".$db_tbl."` WHERE DATEDIFF(CURDATE(), lastactive) >= 14") or die(mysql_error());
$row2 = mysql_fetch_object($sql2);
echo $diff = htmlspecialchars($row2->dagen_offline);
?>
Ik zal het vast wel fout hebben gedaan, omdat ik totaal niet weet hoe ik dit moet gebruiken en ik word ook niet wijs uit de MySQL documentation.
Dit is de output script:
<?
$sql = "SELECT name,active,state,ip,lastactive FROM `".$db_tbl."` ORDER BY name ASC";
$query = mysql_query($sql);
# ! begin test omgeving
$sql2 = mysql_query("SELECT DATEDIFF(CURDATE(), lastactive) AS dagen_offline FROM `".$db_tbl."` WHERE DATEDIFF(CURDATE(), lastactive) >= 14") or die(mysql_error());
$row2 = mysql_fetch_object($sql2);
echo $diff = htmlspecialchars($row2->dagen_offline);
# ! einde test omgeving
while($row = mysql_fetch_object($query)) {
$name = htmlspecialchars($row->name);
$active = htmlspecialchars($row->active);
$state = htmlspecialchars($row->state);
$ip = htmlspecialchars($row->ip);
$lastactive = htmlspecialchars($row->lastactive);
$number = $number + 1;
if($active == 0) {
echo "<tr>\n";
echo "<td><font color=\"red\">".$number." NOT ACTIVE</font></td>\n";
echo "<td>".$name."</td>\n";
echo "<td></td>\n";
echo "<td></td>\n";
echo "<td><font color=\"red\">0000-00-00 00:00:00</font></td>\n";
echo "</tr>\n";
}elseif ($state == 1 && $lastactive != "0000-00-00 00:00:00"){
echo "<tr>\n";
echo "<td><font color=\"green\">".$number." ADMIN</font></td>\n";
echo "<td><a title=\"PM: ".$name."\" href=\"../pm/compose.php?id=".$name."\">".$name."</a></td>\n";
echo "<td><a title=\"View profile\" href=\"profile.php?id=".$name."\">View Profile</a></td>\n";
echo "<td>".$ip."</td>\n";
echo "<td>".$lastactive."</td>\n";
echo "</tr>\n";
}elseif ($state == 0 && $lastactive != "0000-00-00 00:00:00"){
echo "<tr>\n";
echo "<td>".$number."</td>\n";
echo "<td><a title=\"PM: ".$name."\" href=\"../pm/compose.php?id=".$name."\">".$name."</a></td>\n";
echo "<td><a title=\"View profile\" href=\"profile.php?id=".$name."\">View Profile</a></td>\n";
echo "<td>".$ip."</td>\n";
echo "<td>".$lastactive."</td>\n";
echo "</tr>\n";
}elseif ($state == 0 && $lastactive == "0000-00-00 00:00:00") {
echo "<tr>\n";
echo "<td>".$number."</td>\n";
echo "<td><a title=\"PM: ".$name."\" href=\"../pm/compose.php?id=".$name."\">".$name."</a></td>\n";
echo "<td><a title=\"View profile\" href=\"profile.php?id=".$name."\">View Profile</a></td>\n";
echo "<td>".$ip."</td>\n";
echo "<td><font color=\"red\">".$lastactive."</font></td>\n";
echo "</tr>\n";
}
}
?>