Use ASP to easily create daily updates of your own website

Source: Internet
Author: User
Tags exit rand
Use ASP to easily create daily updates of your own website
What is the daily update I think we all should know,
Actually a bit like now many news website's update, below describes how to let your
The content of the website is updated automatically every day
The following code applies to:
1. Use any ODBC-compliant database
2. Easy to insert into your existing ASP program
How do I save updated content?
Database structure: (altogether three fields)
Quoteid (Long), Quote (String), Author (String)
The next tip is how to get updates to appear on any page?
We simply send the updated content and the author back to the calling page.
The code is as follows, where logic is a random number that indicates which record is displayed randomly from the database:
<%
Sub getquote (ByVal strquote, ByVal strauthor)
Dim Intmaxid
Dim Intrecordid
Dim strSQL
Dim oconn
Dim ORS

set oconn = Server.CreateObject ("ADODB. Connection ")
oConn.Open "database=mydb;dsn=quotes; Uid=sa; password=; "

strSQL = "Select Maxid=max (Quoteid) from quotes"
Set ORS = Oconn.execute (strSQL)
If ors.eof Then
Strquote = "Webmaster is too lazy to update the content today."
Strauthor = "hehe"
Exit Sub
Else
Intmaxid = ORS ("Maxid")
End If

Randomize
Intrecordid= Int (RND * intmaxid) + 1
strSQL = "SELECT * from quotes where quoteid=" & Intrecordid & ";"
Set ORS = Oconn.execute (strSQL)
If ors.eof Then
Strquote = "Webmaster is too lazy to update the content today."
Strauthor = "hehe"
Exit Sub
Else
Ors.movefirst
Strquote = ORS ("Quote")
Strauthor = ORS ("Author")
End If

Ors.close
Oconn.close
Set ORS = Nothing
Set oconn = Nothing
End Sub
%>

In fact, if you use a nested SQL in your program, you can improve performance, such as
SELECT * from quotes where Quoteid = (select int (RND * MAX (Quoteid)) from quotes);
The problem is that some databases have random number functions that are rand rather than RND,
If you use it yourself, then of course you can use this to replace the method I described above,
But don't forget, if someone else's database doesn't support Rand, huh?
Again, now is talking about ASP technology, rather than talking about SQL technology, hehe.
Now we're going to save the above code in a file called Quotes.inc,
Here's an example of how to invoke it:
<HTML>
<HEAD>
<TITLE> Example </TITLE>
<!--#include virtual = "Quotes.inc"-->
</HEAD>
<BODY>
<BR><BR>
<%
Dim Strquote
Dim Strauthor
GetQuote (Strquote, Strauthor)
%>
<table border=0 cellpadding=6 cellspacing=5 bgcolor= "#000000" width=500>
<tr bgcolor= "#CCCCCC" >
&LT;TD align=center>
<B> "<% =strquote%>" <br>--<i><% =strauthor%></i></b>
</TD>
</TR>
</TABLE>
<BR><BR>
</BODY>
</HTML>
In fact you can strengthen the point of its function:
1. You can format the returned string in a child procedure so that it looks more beautiful
2. This code is made into a component to invoke the
3. Use a text file to replace the database
4. Putting SQL in a stored procedure


Related Article

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.