Developer on Alibaba Coud: Build your first app with APIs, SDKs, and tutorials on the Alibaba Cloud. Read more ＞
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
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")
<meta http-equiv= "Refresh" content= "4" > refresh every four seconds
Please save this program as Chatview.asp
This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or
reliability of the article or any translations thereof. If you have any concerns or complaints relating to the article, please send an email, providing a detailed description of the concern or
complaint, to email@example.com. A staff member will contact you within 5 working days. Once verified, infringing content will be removed immediately.
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:
and provide relevant evidence. A staff member will contact you within 5 working days.