Simplified the Code further and updated to remove the old members from the Read List (FIFO), when the limit of 255 is reached for the field.
Dim LenWhoViewed,Topic_WhoViewed,DoUpdate,TmpWhoViewed,UpdateTview,IDToDiscard
if MemberID = 0 or IsNull(MemberID) or MemberID < 0 then
'dont update anything
else
DoUpdate = True
strsql = "SELECT T.T_WHOVIEWED FROM " & strActivePrefix & "TOPICS T WHERE "
strsql = strsql & "T.TOPIC_ID=" & Topic_ID
set tviewRS = Server.CreateObject("ADODB.RecordSet")
tviewRS.open strsql, my_conn, 3
Topic_WhoViewed = tviewRS("T_WHOVIEWED")
tviewRS.close
set tviewRS = nothing
if IsNull(Topic_WhoViewed) or Topic_WhoViewed = "" or Topic_WhoViewed = "0" or Len(Trim(Topic_WhoViewed)) = 0 then
UpdateTview = MemberID
else
LenWhoViewed = len(Topic_WhoViewed)
arrWhoViewed = split(Topic_WhoViewed,",",-1,1)
'CHECK if the MemberID already Exists
if IsArray(arrWhoViewed) then
If Instr(1,Topic_WhoViewed, "," & MemberID & ",",1) > 0 or _
Trim(arrWhoViewed(lbound(arrWhoViewed))) = Trim(MemberID) or _
Trim(arrWhoViewed(ubound(arrWhoViewed))) = Trim(MemberID) then
DoUpDate = false
end if
else
if Trim(Topic_WhoViewed) = Trim(MemberID) then DoUpdate = false
end if
'CHECK if Field is Full. If Full then discard the
'Oldest MemberID(FIFO)
if DoUpdate = True then
if (LenWhoViewed + len(MemberID) = 255) or _
(LenWhoViewed + len(MemberID) > 255) then 'Max Limit
IDToDiscard = left(Topic_WhoViewed,(instr(len(MemberID),Topic_WhoViewed,",",1)))
if IDToDiscard <> MemberID & "," then
TmpWhoViewed = Replace (Topic_WhoViewed,IDToDiscard,"",1,1,1)
Topic_WhoViewed = TmpWhoViewed
DoUpdate = True
else
DoUpdate = false
end if
end if
end if
if DoUpDate = True then
UpdateTview = Topic_WhoViewed & "," & MemberID
end if
end if
'UPDATE the Database
if DOUpdate = true then
strsql = "UPDATE " & strActivePrefix & "TOPICS "
strsql = strsql & "SET " & strActivePrefix & "TOPICS.T_WHOVIEWED = '" & UpdateTview & "' WHERE "
strsql = strsql & strActivePrefix & "TOPICS.TOPIC_ID = " & Topic_ID
my_conn.execute(strsql)
end if
LenWhoViewed = ""
end if
GauravBhabu
There is only one miracle...That is LIFE! | It is difficult to IMPROVE on Perfection, There is no harm in Keep Trying.
Edited by - GauravBhabu on 21 November 2001 15:40:55