From: Daevid Vincent Date: August 5 2006 12:41am Subject: RE: FW: How do I find all the users that are new since my last login (repost) List-Archive: http://lists.mysql.com/mysql/200668 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I've thought about this a bit more since last night, and it seems that I = can just use the built in 'CURRENT_DATE' (sp?) as it's a given that if = they're logged in, then they're logged in NOW() which is =3D=3D CURRENT_DATE = minus the hh:mm:ss. I guess I could also store in a session (this is in PHP) the = 'login_date' BEFORE I update it with the current info. So effectively, that would be = the LAST login date right? Then I need to whip up some SQL to compare all users created_on date = BETWEEN that 'LAST' date and CURRENT_DATE? D=C6VID =20 > -----Original Message----- > From: Martin Jespersen [mailto:mbj@stripped]=20 > Sent: Friday, August 04, 2006 5:35 PM > To: Daevid Vincent > Cc: mysql@stripped > Subject: Re: FW: How do I find all the users that are new=20 > since my last login (repost) >=20 > You could add an extra field called last_login_date which=20 > you'd set only=20 > once per session - at login time. At login time you'd set this to the=20 > value that exists in login_date. Then use that for comparison against=20 > created_on. >=20 > Daevid Vincent wrote: > > I have a SQL challenge I'm not sure how to solve. But it's=20 > so common, I feel > > kind of stupid asking this... > >=20 > > I have a 'user' table with 'login_date' which is an auto=20 > updated DATETIME > > column and a 'created_on' which is a DATETIME (but not=20 > updated after the > > record is created the first time) > >=20 > > I want to show a list of users who are new since my last=20 > login. But the > > problem is that my last login changes for every page load=20 > (i.e. it is > > updated so that I can guestimate if a user is logged in=20 > still or not... I > > consider 10m to be the window, since rarely do users ever officially > > 'logout'). > >=20 > > So I think I need to have a SQL query that only deals with=20 > the date, not the > > mins/secs? I'm just not sure the optimum way to do this. > >=20 > > The other challenging part seems to me that as soon as=20 > 'login_date' is > > updated, then everyone that was 'new' is now 'old' because=20 > the login_date > > just got updated right? I kinda want the 'new' user status=20 > to persist for > > the whole session [or maybe even the whole day (that is, I=20 > could logout/in > > and those people would still show as new) -- but I can live=20 > with just being > > new for the session] > >=20 > > How is this sort of thing usually handled? Do I need=20 > another column that > > isn't auto-updated and that just get's set upon each new=20 > 'login' session? > > Unlike a "message board" or web based "email" system, I=20 > CAN'T flag each user > > as viewed or something like that. This feature is for a=20 > "network" type > > scenario where a user can see new users added to their=20 > network of friends > > since the last time they logged in. Or so the=20 > Administrators can see all new > > users. This type of thing. > >=20 > >=20 > > =D0=C65=CF=D0=20 > >=20 > >=20 >=20