ASP Instant Messaging, Part 3
By Ryan S.
Read Part 1
Read Part 2
In Part 2 we looked at how to check for and
send messages on the client. In this part we'll examine how to display users'
messages on an ASP page.
Presented below is the code to display the users messages, which appears in an ASP
Nugget in the center frame.
<html>
<head>
<title>Chat center (Not Displayed</title>
<meta http-equiv="refresh" content="5">
<!-- This is crucial to ensure
timely delivery of messages -->
</head>
<body bgcolor="white">
<%
Call CheckMsgs
If not (cChatDB.BOF) Then
cChatDB.MoveFirst
End If
If not cChatDB.EOF Then
strFilter = "(ToID = " & Session("UserID") & " and FromID=" & _
Request.QueryString("TalkingTo") & ") or (ToID=" & _
Request.QueryString("TalkingTo") & " and FromID=" & _
Session("UserID") & ")"
cChatDB.Filter = strFilter
cChatDB.Sort = "TimeSent DESC"
If not cChatDB.EOF Then
response.write "<table">
if PMIN(Session("Count")) Then
Session("Count") = 10
End If
Count = 0
Do While not cChatDB.EOF and Count <= cint(Session("Count"))
response.write "<tr valign=top width=300>"
response.write "<td valign=top width=50>"
if lcase(cChatDB("FromName")) = lcase(Session("UserName")) Then
response.write "<font color=red>" & cChatDB("FromName")
Else
response.write "font color=blue>" & cChatDB("FromName")
End If
response.write "</font></td>"
response.write "<td rowspan=2 valign=top width=250>" & _
cChatDB("Message") & "</td></tr>"
response.write "<tr valign=top width=300>"
response.write " <td valign=top width=50>"
zH = Hour(cChatDB("TimeSent")
zM = Minute(cChatDB("TimeSent"))
zS = Second(cChatDB("TimeSent"))
If zH > 12 Then
zH = zH - 12
End If
If zM < 10 Then
zM = "0" & zM
End If
If zS < 10 Then
zS = "0" & zS
End If
response.write zH & ":" & zM & ":" & zS
response.write "</td></tr>"
count = count + 1
cChatDB.MoveNext
Loop
response.write "</table>"
End If
End If
%>
|