I'm trying to query a table where attendance records are kept per user and group. If the lastest timestamp per user and group is two weeks older than today's date, then an image will show. Here is the code I have at this point but I don't think I'm understanding the time formats or something.
$tsquery = mysql_query("SELECT ts FROM `attendance` WHERE contact_id='$contactid' AND group_id='$groupid' AND `ts` + INTERVAL 7 DAY < NOW() ORDER BY ts LIMIT 1 ");
$ts=mysql_fetch_array($tsquery);
if(isset($ts)){
echo "<img src='images/care.png' title='Care Group' style='border: none; background-color: #fff;'>";
} else {
}
I'm getting false results on some people. If someone didn't attend an event 2 weeks ago, but did attend an event yesterday, it's returning true rather than finding that they were in attendance within the last two weeks. Is there a better way of doing this that would return more accurate results?