|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today! |
|
#1
|
|||
|
|||
|
Trying to query records less than six months old but older than 30 days.
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: Code:
('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: Code:
$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 '';}
}
}
|
|
#2
|
||||
|
||||
|
ok havent actually tried this out, but how about something like:
PHP Code:
__________________
When I die, I want to go peacefully like my Grandfather did, in his sleep -- not screaming, like the passengers in his car. |
|
#3
|
|||
|
|||
|
Thanks DavidMR, but that would select every user between six months and thirty days ago (including the ones that have logged in recently). I was trying to select the users who logged in six mon to 30 days ago and compare that to the users who have logged in less then thirty days ago.
The solution below works but is a little slow. Any ideas on how to make it faster? Code:
$get_thirtyday_login = "SELECT s1.UserName, s1.DateTime FROM salesloginlog AS s1 WHERE s1.DateTime = (SELECT max(s2.DateTime) FROM salesloginlog AS s2 WHERE s2.UserName = s1.UserName) AND s1.DateTime <= '$twentynine_days_ago' AND s1.DateTime >= '$six_months_ago'"; |
|
#4
|
|||
|
|||
|
Sorry double posted.
|
|
#5
|
||||
|
||||
|
sorry if im not getting this right, but could you use 2 betweens?
PHP Code:
the numbers in the variables etc, -6 and -29 can be changed to change the ranges... |
|
#6
|
|||
|
|||
|
On the date ('2008/04/13 02:59:48 PM') try the following php function:
strtotime( String $time ); Usage: strtotime('2008/04/13 02:59:48 PM'); //returns that date/time as a unix timestamp (seconds from epoch). PHP Code:
__________________
-gmt2001 |
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > Trying to query records less than six months old but older than 30 days. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|