I humbly ask for your assistance.
I've got a field in my mySQL database for when the record was last updated. It is of the type "timestamp(8)". Now what I'd really like to do is display a rating according to how old the record is (and hence how reliable it may be) by somehow figuring out the difference in time between that timestamp(8) "lastupdated" and today's date.
Here are two different attempts. Neither worked.
Attempt 1...
$query = "SELECT * FROM alumni WHERE lastname RLIKE '^[$lastname]' ORDER BY lastname LIMIT $limit,$per_page";
$result = mysql_query ($query);
$stalequery = "SELECT (TO_DAYS(NOW())-TO_DAYS(FOM_UNIXTIME(lastupdated))) AS days_stale FROM alumni";
$staleresult = mysql_query ($stalequery);
if ($days_stale>=0 && $days_stale<=29) {
$stalerating = "10NEW";}
if ($days_stale>=30 && $days_stale<=179) {
$stalerating = "10";}
if ($days_stale>=180 && $days_stale<=359) {
$stalerating = "9";}
if ($days_stale>=360 && $days_stale<=539) {
$stalerating = "8";}
if ($days_stale>=540 && $days_stale<=719) {
$stalerating = "7";}
if ($days_stale>=720 && $days_stale<=899) {
$stalerating = "6";}
if ($days_stale>=900 && $days_stale<=1079) {
$stalerating = "5";}
if ($days_stale>=1080 && $days_stale<=1259) {
$stalerating = "4";}
if ($days_stale>=1260 && $days_stale<=1439) {
$stalerating = "3";}
if ($days_stale>=1440 && $days_stale<=1619) {
$stalerating = "2";}
if ($days_stale>=1619) {
$stalerating = "1";}
else $stalerating = "zero or not working";
if (@mysql_num_rows($result))
{
print "<table .....
Here's the link to attempt #1 Everything comes out as zero.
Then I tried this other code...
$query = "SELECT * FROM alumni WHERE lastname RLIKE '^[$lastname]' ORDER BY lastname LIMIT $limit,$per_page";
$result = mysql_query ($query);
$stalequery = "SELECT (TO_DAYS(NOW())-TO_DAYS(FOM_UNIXTIME(lastupdated))) AS days_stale FROM alumni";
list($days_stale) = mysql_fetch_row(mysql_query($stalequery));
if ($days_stale < 0) $stalerating = "error: <0";
elseif ($days_stale < 30) $stalerating = "10NEW";
elseif ($days_stale < 180) $stalerating = "10";
elseif ($days_stale < 360) $stalerating = "9";
elseif ($days_stale < 540) $stalerating = "8";
elseif ($days_stale < 720) $stalerating = "7";
elseif ($days_stale < 900) $stalerating = "6";
elseif ($days_stale < 1080) $stalerating = "5";
elseif ($days_stale < 1260) $stalerating = "4";
elseif ($days_stale < 1440) $stalerating = "3";
elseif ($days_stale < 1620) $stalerating = "2";
else $stalerating = "1";
Here's the link to attempt #2 This one everything comes out as "10NEW" and has an error message about the line list($days_stale) = mysql_fetch_row(mysql_query($stalequery));
Anybody here have any ideas on either what I'm doing wrong or any alternate suggestions? Thanks a bunch for your help.