Chat Room Construction detailed four

Source: Internet
Author: User
Tags expression client
When we save the above program in a server directory with Execute permissions, we see the same user login interface as the usual chat room when the client opens in a browser. We then enter the username and password, as we send, the information we enter will be stored in the user database. Then there appeared the basket, we tried to enter a word, click on the button, then we will speak with the words we have entered, we choose the speaker, our choice of color and expression in the speech database. However, after the speech, we did not find any statements appear on the screen, because: The program itself is responsible for the pure to write the database to the database, he will not return anything to the client, unless your input is wrong.
Chat rooms also require an important program that automatically and continuously reads the latest records in the database and displays them on all users ' browsers. This program has nothing to do with any other program, his only task is to read the data in the speech database, show him out, regardless of whether the customer entered the speech, no matter who the customer spoke to, regardless of the customer chooses what expression and color. When this chat room even does not have a person to speak, this program also is unceasingly reads this database, every n seconds refreshes, this n is decided by the programmer.
From this, we know: The landing _ Speech part and the automatic refresh part is not any connection.
Before analyzing the sample program, we'd better analyze some of the following:
1. When we write the database to the database, the record is continuously added to the end of the datasheet, so we have to know which sentence is up to date, which sentence is in front, we know that in the MSAccess database table, there is an AutoNumber field ID, this field is very useful, The maximum ID record is the most recently entered record, each add a record, ID automatically add 1, thus, we can through the ID to the user's words from the new to the old, a sentence of the sorted output. We know that in the SQL select language, there is a clause of order by, in which he sorts the results in ascending or descending order, in one or more columns. If we don't use the order by, the select defaults to ascending output, and we see that the oldest speeches are always shown in the front, and the newest ones go to the end, which is certainly not what we want.
2, a little more, that is, users continue to enter the database into the statement, the database will become more and more, and we for the speed, we can not and do not have to read all the records to display all the words, we just need to see the latest n words such as the latest 50 words is enough. How to achieve the above two points, and take a look at the sample program:

Let's analyze the following procedure: chatview.asp

<%Response.Buffer=true%> Set Cache to True

<% Specify Database
Set conn=server.createobject ("ADODB. Connection ")
Connstr= "dbq=" +server.mappath ("Chat.mdb") + ";D river={microsoft Access DRIVER (*.mdb)};"
Conn.Open ConnStr
%>

<%
Sql= "SELECT * from chat table order by ID DESC" Descending output query results
Set Rootrs=conn. Execute (SQL)
Set Name=rootrs ("name") gets the name, speech, color, expression, etc. from the database
Set Word=rootrs ("Talking")
Set Colo=rootrs ("Color")
Set Face=rootrs ("facial expression")
Set Who=rootrs ("Speech object")
%>

<%i=0%> Define output record number I


<%do while not rootrs.eof and i<=50%> display 50 words, including name, Word, color, expression, etc.
<%i=i+1%>
<table border= ' 0 ' cellpadding= ' 0 ' cellspacing= ' 0 ' width= ' 85% ' ><tr>
&LT;TD width= ' 100% ' bgcolor= ' #C0C0C0 ' ></td></tr><tr><td width= ' 100% ' >
<font color= ' #0000FF ' ><strong><%=name%></font></strong><font color= ' #008080 ' ><%=face%></font><font color= ' #0000FF ' ><strong><%=who%> said:
</font></strong><font color= ' <%=colo%> ' ><%=word%>
</font></td></tr><tr>
&LT;TD width= ' 100% ' bgcolor= ' #C0C0C0 ' ></td></tr></table><br>
<%rootrs.movenext
Loop%>

<meta http-equiv= "Refresh" content= "4" > refresh every four seconds


Please save this program as Chatview.asp


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.