Click rate of Statistics pictures

Source: Internet
Author: User
Tags dsn insert query variable access database
If you're like me, your home page is for a variety of picture services, it's quite necessary to know which pictures are popular and which are not popular. Here, to tell you about how I use ASP to solve this problem.

Let's analyze it first. Generally as a picture site, the first display is a number of small size thumbnails, click to show a large image. Therefore, we can in small map and large map of the link between the fuss, so that the small map of the link to an ASP file, by this ASP file will be clicked down, and then show a big picture, the principle is quite simple.

First, we're going to create a database file for recording clicks, I'm using ACCESS97, and other databases are OK. In this library, only need a table, name is called 1 bar. There are three database fields: Picturename (character), Clicktimes (digital), StartTime (date type), the first is the name of the picture, the second is the total number of clicks, and the third is the time of the first click. Note that the field name cannot be in Chinese.

After the library is built, the next step is the preparation of the interface and program. Create a new HTML file in FrontPage2000, insert a few pictures, and shrink it into small graphs and save it in thumbnail function. To create a new ASP file, its source code is as follows:

<% server.scripttimeout = 60//Set timeout
Response.Expires =0%>//Set page expiration to 0
<!--#include file =″ado Vbs.inc″-->//Enter the VB constant description file
<%
Dim picturename1,clicktimes1,starttime1//Declare the variable used to hold the data.
Dim Connection,record//declares the variable used to open the database.
picturename1= request.querystring (″picturename″)//Gets the name of the picture.
Set connection = Server.CreateObject (″adodb. Connection″)
Set record= Server.CreateObject (″adodb. Recordset″)
record.locktype=3//Set How the Record object is locked
record.cursortype=adopenforwardonly//Set cursor orientation only forward
DSN = Server. MapPath (″access.dsn″)//Get ACCESS.DSN on the server's path
Mdb=server.mappath (″click.mdb″)//Get Click.mdb path
Mydsn=″ Filedsn=″+dsn+″;d Bq=″+mdb+″;″
Connection. Open MyDSN
//These are the operations that open the database. Where Access.dsn is a configuration file for an Access database.

Below, we want to get the number of clicks corresponding to the name of the picture in the database. First look in the library to see if there is a name.
Sql=″select * from 1 where picturename=′″&picturename1&″′″//constructs the SQL statement.
Record.open SQL, connection//Execute SQL query
After the query, we have to determine if there is a corresponding record in the library. If not, create a new one:
If record. Eof=true Then
Thistime=1
Currenttime=date
Record.close ()//Close the Record object, and then reopen it in another way
Sql=″insert into 1 (picname,clicktimes,starttime) VALUES (′″&picturename1&″′,′″&thistime&″′,′″&currenttime&″′) ″′ Building SQL INSERT Statements
Set Record=connection. Execute (SQL)
Else
Totaltimes=cint (Record (″clicktimes″))//from the database to get the number of hits previously saved
Totaltimes=totaltimes+1//Plus this one
Record (″clicktimes″) =totoletimes//re-assignment
Record.updata ()//Update records in the database
endif
%>

Above, click on the record of the work is basically completed, do not forget, but also to show the figure. This is also very simple, just add a sentence of > on <body> and </body>. If you need to, you can also write the total number of clicks: <% Response.Write Picturename1&″ This picture has been clicked ″&totaltimes&″ times ″%>

So far, the ASP section is complete. There are minor changes in the previous HTML file. Put all the
<a href=″ filename ″></a>

All changed to <a href=″jilu.asp?picturename= file name ></a> where jilu.asp is the ASP filename.

If you're recording clicks, these are basically enough. But the results of this record need to be downloaded to know, it seems a bit too primitive. So the following is also added to the function of online statistics.

The program used for statistics should be able to arrange records in ascending or descending order, showing the number of clicks per day, and if there are too many entries, it is necessary to add the paging function.

View statistics just let the webmaster do the work, so set a password is very necessary. So, create a new HTML file, and insert a form:

<form method=″post″action=″tongji.asp″>
<p><input type=″radio″value=″ l ″checked name=″R1″> Ascending order
<input Type=″radio″name=″r1″value=″ Drop ″> descending order </p>
<p><input Type=″text″name=″t1″ Size=″20″><input Type=″submit″value=″ Submit ″name=″b1″><input Type=″reset″value=″ all rewrite ″name=″b2″></p
<p> </p>
</form>

The following is the contents of the tongji.asp:
<%
if (request). From (T1) <>″1234″) then
Response.write″ you can't enter!!! ″
Response.End
End If
Set connection = Server.CreateObject (″adodb. Connection″)
Set record= Server.CreateObject (″adodb. Recordset″)
record.locktype=3
record.cursortype=adopenforwardonly
DSN =server. MapPath (″access.dsn″)
Mdb=server.mappath (″click.mdb″)
Mydsn=″filedsn=″+dsn+″;d Bq=″+mdb+″;″
Connection . Open MyDSN
If request. Form (R1) =″ l ″then
Sql=″select * from 1 ORDER by Clicktimes″
Else
Sql=″select * to 1 ORDER by Clicktim Es desc″
End If
Record.open sql,connection//Execute SQL
cuttenttime=date
%>

Here is the section shown, where a table is used to separate the various data:
<table border=″1″width=″100%″>
<%while record.eof =false
The If record (″clicktimes″) =0 the then record. MoveNext%>//There are some data in the database that are not normal and want to exclude them.
<tr>
<TD Width=″33%″><%=record (″picname″)%> </td>
<TD Width=″33%″><%=record (″clicktimes″)%> </td>
<TD width=″34%″><%=csng (″clicktimes″)/(DateDiff (″d″,record (″starttime″), currenttime,0,0) +1)) > </td>
</tr>
<%
Record. MoveNext//Cursors Move Down
Wend%>
</table>

Here, a simple picture Click Record, Statistics of the ASP program is completed, I hope everyone on this basis embellish.



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.