Author |
Topic |
|
redbrad0
Advanced Member
USA
3725 Posts |
Posted - 13 April 2001 : 17:50:21
|
this code runs on every single page on my site and was wondering if someone could think of a better way to write it?
strActiveUsersCheckOutTime = DATEADD("s", -1000, Now)
if strDBNTUserName = "" then strActiveUserName = "n/a" else strActiveUserName = strDBNTUserName end if
strSQL = "SELECT " & strMemberTablePrefix & "Active_Users.A_MEMBER_USERNAME, " & strMemberTablePrefix & "Active_Users.A_LAST_CHECKIN " strSQL = strSQL & "FROM " & strMemberTablePrefix & "Active_Users " strSQL = strSQL & "WHERE " & strMemberTablePrefix & "Active_Users.A_SESSION_ID='" & strUserSessionID & "'" set rs = my_Conn.Execute (strSQL)
if rs.eof or rs.bof then '// THEY ARE NOT IN THE DATABASE SO LETS ADD THEM
strSQL = "INSERT INTO " & strMemberTablePrefix & "Active_Users (A_MEMBER_ID,A_MEMBER_USERNAME,A_SESSION_ID,A_CHECKIN,A_LAST_CHECKIN) VALUES ('" strSQL = strSQL & strDBNTUserID & "','" & strActiveUserName & "','" & strUserSessionID & "','" & Now & "','" & Now & "')" my_Conn.Execute (strSQL) else '// THEY ARE IN THE DATABASE SO LETS UPDATE THERE STUFF
'// FIRST LETS MAKE SURE THEY ARE NOT SUPOSED TO BE TIMED OUT strSQL = "SELECT " & strMemberTablePrefix & "Active_Users.A_LAST_CHECKIN " strSQL = strSQL & "FROM " & strMemberTablePrefix & "Active_Users " strSQL = strSQL & "WHERE " & strMemberTablePrefix & "Active_Users.A_SESSION_ID = '" & strUserSessionID & "' " strSQL = strSQL & "AND " & strMemberTablePrefix & "Active_Users.A_LAST_CHECKIN < '" & strActiveUsersCheckOutTime & "' " set rs2 = my_Conn.Execute (strSQL)
if rs2.eof or rs2.bof then '// NOW LETS UPDATE THEM SINCE THEY ARE NOT SUPOSED TO BE TIMED OUT strSQL = "UPDATE " & strMemberTablePrefix & "Active_Users SET " & strMemberTablePrefix & "Active_Users.A_LAST_CHECKIN='" & Now & "', " & strMemberTablePrefix & "Active_Users.A_MEMBER_USERNAME='" & strActiveUserName & "', " & strMemberTablePrefix & "Active_Users.A_MEMBER_ID='" & strDBNTUserID & "' WHERE " & strMemberTablePrefix & "Active_Users.A_SESSION_ID='" & strUserSessionID & "'" my_Conn.Execute (strSQL) else '// DELETE THEM strSQL = "DELETE FROM " & strMemberTablePrefix & "Active_Users " strSQL = strSQL & "WHERE " & strMemberTablePrefix & "Active_Users.A_SESSION_ID = '" & strUserSessionID & "' " strSQL = strSQL & "AND " & strMemberTablePrefix & "Active_Users.A_LAST_CHECKIN < '" & Now & "' " my_Conn.Execute (strSQL)
strSQL = "INSERT INTO " & strMemberTablePrefix & "Active_Users (A_MEMBER_ID,A_MEMBER_USERNAME,A_SESSION_ID,A_CHECKIN,A_LAST_CHECKIN) VALUES ('" strSQL = strSQL & strDBNTUserID & "','" & strActiveUserName & "','" & strUserSessionID & "','" & Now & "','" & Now & "')" my_Conn.Execute (strSQL)
end if end if
'// LETS DELETE ALL INACTIVE USERS strSQL = "DELETE FROM " & strMemberTablePrefix & "Active_Users WHERE A_LAST_CHECKIN < '" & strActiveUsersCheckOutTime & "'" my_Conn.Execute (strSQL)
Brad |
|
HuwR
Forum Admin
United Kingdom
20584 Posts |
Posted - 13 April 2001 : 18:31:40
|
try this
strActiveUsersCheckOutTime = DATEADD("s", -1000, Now)
if strDBNTUserName = "" then strActiveUserName = "n/a" else strActiveUserName = strDBNTUserName end if
strSQL = "SELECT " & strMemberTablePrefix & "Active_Users.A_MEMBER_USERNAME, " & strMemberTablePrefix & "Active_Users.A_LAST_CHECKIN " strSQL = strSQL & "FROM " & strMemberTablePrefix & "Active_Users " strSQL = strSQL & "WHERE " & strMemberTablePrefix & "Active_Users.A_SESSION_ID='" & strUserSessionID & "'" set rs = my_Conn.Execute (strSQL)
if rs.eof or rs.bof then '// THEY ARE NOT IN THE DATABASE SO LETS ADD THEM strSQL = "INSERT INTO " & strMemberTablePrefix & "Active_Users (A_MEMBER_ID,A_MEMBER_USERNAME,A_SESSION_ID,A_CHECKIN,A_LAST_CHECKIN) VALUES ('" strSQL = strSQL & strDBNTUserID & "','" & strActiveUserName & "','" & strUserSessionID & "','" & Now & "','" & Now & "')" my_Conn.Execute (strSQL) else '// THEY ARE IN THE DATABASE SO LETS UPDATE THERE STUFF
'// FIRST LETS MAKE SURE THEY ARE NOT SUPOSED TO BE TIMED OUT if rs("A_LAST_CHECKIN") < strActiveUsersCheckOutTime '// NOW LETS UPDATE THEM SINCE THEY ARE NOT SUPOSED TO BE TIMED OUT strSQL = "UPDATE " & strMemberTablePrefix & "Active_Users SET " & strMemberTablePrefix & "Active_Users.A_LAST_CHECKIN='" & Now & "', " & strMemberTablePrefix & "Active_Users.A_MEMBER_USERNAME='" & strActiveUserName & "', " & strMemberTablePrefix & "Active_Users.A_MEMBER_ID='" & strDBNTUserID & "' WHERE " & strMemberTablePrefix & "Active_Users.A_SESSION_ID='" & strUserSessionID & "'" my_Conn.Execute (strSQL) else '// DELETE THEM strSQL = "DELETE FROM " & strMemberTablePrefix & "Active_Users " strSQL = strSQL & "WHERE " & strMemberTablePrefix & "Active_Users.A_SESSION_ID = '" & strUserSessionID & "' " strSQL = strSQL & "AND " & strMemberTablePrefix & "Active_Users.A_LAST_CHECKIN < '" & Now & "' " my_Conn.Execute (strSQL) end if end if
'// LETS DELETE ALL INACTIVE USERS strSQL = "DELETE FROM " & strMemberTablePrefix & "Active_Users WHERE A_LAST_CHECKIN < '" & strActiveUsersCheckOutTime & "'" my_Conn.Execute (strSQL)
|
|
|
redbrad0
Advanced Member
USA
3725 Posts |
Posted - 13 April 2001 : 18:39:47
|
oh thanks huwr, i thought i was probley missing something
Brad |
|
|
redbrad0
Advanced Member
USA
3725 Posts |
Posted - 13 April 2001 : 18:48:51
|
quote:
strActiveUsersCheckOutTime = DATEADD("s", -1000, Now)
if strDBNTUserName = "" then strActiveUserName = "n/a" else strActiveUserName = strDBNTUserName end if
strSQL = "SELECT " & strMemberTablePrefix & "Active_Users.A_MEMBER_USERNAME, " & strMemberTablePrefix & "Active_Users.A_LAST_CHECKIN " strSQL = strSQL & "FROM " & strMemberTablePrefix & "Active_Users " strSQL = strSQL & "WHERE " & strMemberTablePrefix & "Active_Users.A_SESSION_ID='" & strUserSessionID & "'" set rs = my_Conn.Execute (strSQL)
if rs.eof or rs.bof then '// THEY ARE NOT IN THE DATABASE SO LETS ADD THEM strSQL = "INSERT INTO " & strMemberTablePrefix & "Active_Users (A_MEMBER_ID,A_MEMBER_USERNAME,A_SESSION_ID,A_CHECKIN,A_LAST_CHECKIN) VALUES ('" strSQL = strSQL & strDBNTUserID & "','" & strActiveUserName & "','" & strUserSessionID & "','" & Now & "','" & Now & "')" my_Conn.Execute (strSQL) else '// THEY ARE IN THE DATABASE SO LETS UPDATE THERE STUFF
'// FIRST LETS MAKE SURE THEY ARE NOT SUPOSED TO BE TIMED OUT if rs("A_LAST_CHECKIN") < strActiveUsersCheckOutTime THEN '// NOW LETS UPDATE THEM SINCE THEY ARE NOT SUPOSED TO BE TIMED OUT strSQL = "UPDATE " & strMemberTablePrefix & "Active_Users SET " & strMemberTablePrefix & "Active_Users.A_LAST_CHECKIN='" & Now & "', " & strMemberTablePrefix & "Active_Users.A_MEMBER_USERNAME='" & strActiveUserName & "', " & strMemberTablePrefix & "Active_Users.A_MEMBER_ID='" & strDBNTUserID & "' WHERE " & strMemberTablePrefix & "Active_Users.A_SESSION_ID='" & strUserSessionID & "'" my_Conn.Execute (strSQL) else '// DELETE THEM strSQL = "DELETE FROM " & strMemberTablePrefix & "Active_Users " strSQL = strSQL & "WHERE " & strMemberTablePrefix & "Active_Users.A_SESSION_ID = '" & strUserSessionID & "' " strSQL = strSQL & "AND " & strMemberTablePrefix & "Active_Users.A_LAST_CHECKIN < '" & Now & "' " my_Conn.Execute (strSQL) end if end if
'// LETS DELETE ALL INACTIVE USERS strSQL = "DELETE FROM " & strMemberTablePrefix & "Active_Users WHERE A_LAST_CHECKIN < '" & strActiveUsersCheckOutTime & "'" my_Conn.Execute (strSQL)
oh you were so close to being perfect i know you probley dont care but ill just post what was left off incase for some odd reason someone would like to use this code.
Brad |
|
|
|
Topic |
|
|
|