Trying to query users that haven't logged in for at least thirty days but not more than six months ago.
Table structure is datetime - username:
('2008/04/13 02:59:48 PM', 'user3'),
('2008/02/18 03:03:13 PM', 'user99'),
('2008/02/18 02:59:48 PM', 'user3'),
Because user3 has logged in recently the code should only display user99. I can only get it to display all the records or no records.
Here are the queries:
$twentynine_days_ago = date("Y/m/d", strtotime("-29 days"))."\n";
$six_months_ago = date("Y/m/d", strtotime("-180 days"))."\n";
$get_thirtyday_login = "SELECT UserName FROM salesloginlog WHERE DateTime BETWEEN '$six_months_ago' AND '$twentynine_days_ago' ORDER BY UserName DESC";
$result_thirtyday_login=mysql_query($get_thirtyday_login);
while ($row_thirtyday_login = mysql_fetch_assoc($result_thirtyday_login))
{
$thirty_day = $row_thirtyday_login['UserName'];
$get_last_login = "SELECT UserName, DateTime FROM salesloginlog WHERE UserName = '$thirty_day' AND DateTime > '$twentynine_days_ago' ORDER BY UserName DESC LIMIT 1";
$result_last_login=mysql_query($get_last_login);
while ($row_last_login = mysql_fetch_assoc($result_last_login))
{
$last = $row_last_login['UserName'];
if ($last == ''){
echo "$thirty_day<br>";
}
else{
echo '';}
}
}