In fact, AJAX is not something that can be achieved simply by writing JS. You must still have certain programming experience. Otherwise, even if you write it, the idea is not clear and you will not know where to start when you want to make changes in the future. .So after I briefly came into contact with object-oriented programming, I felt that it was really not easy to do well in AJAX. Why did I mention AJAX when I wrote the ASP paging tutorial? Because we need to practice more about the importance of structure in the programming process.
In addition, many friends have deep feelings about paging, so they have never dared to touch it. They either use components written by others, or modify other people's things. Especially for .net, I feel deeply that if you want to quickly When developing a project, I think .net is a very excellent platform. However, Because it is heavily controlled, novices cannot get into the idea of programming and cannot find the feeling of programming at all, as if they are building blocks. Sometimes you still need to practice low-level things, so that your personal technical ability can be improved. Get improved. I don't want to be an assembler who can only use .NET.
Okay, here is the source code of ASP paging for everyone. It has been commented in detail and can generally be understood.
Because this is tutorial one, I’ll start from the simplest one. I directly use AbsolutePage to define the current page, so I don’t use more complicated cursor methods such as MoveFirst, and I also use drop-down selection boxes for paging. I’ll wait for the next tutorial. I will write another advanced paging method, giving a method to advance ten pages, go back ten pages, and only display the current ten page group.
Although ASP is an outdated thing, because it can be written using JS, I feel that when doing a project DEMO, using ASP is more convenient than .NET or JAVA, because it does not need to install a huge environment. Simple Just configure it. If you really need to develop a large-scale project, I will definitely use .NET or JAVA, because this will involve efficiency issues.
Copy the code code as follows:
<%@LANGUAGE=JAVASCRIPT CODEPAGE=936%>
<%
//Define database connection statement
var connstring = Provider=Microsoft.Jet.OLEDB.4.0;Data Source=
+Server.MapPath(database/vote.mdb);
//Create a rs database query
var rs = Server.CreateObject(ADODB.Recordset)
//rs connection method
rs.ActiveConnection = connstring
//rs query statement (query in reverse order of user submission time)
rs.Source = select * from users order by usetime DESC
//Define database query mode
rs.CursorType = 3
rs.CursorLocation = 3
rs.LockType = 1
//Define the amount of data displayed on each page
rs.PageSize = 10
//Open database connection
rs.Open()
//Define the total number of database records, total number of pages, and URL path
var counts,pagecos,thisUrl
counts = rs.RecordCount
pagecos = rs.PageCount
thisUrl = Request.ServerVariables(URL)
//Execute if the cursor is in the table
if(!rs.EOF || !rs.BOF){
//Execute if the page parameter of the url is not empty
if(Request(page).Count != 0){
//Define the default link string, first page, last page, previous page, next page
//The page value of the URL (the specified current page), the current page, the current number of data displayed on each page
var defaltStr,firstpage,lastpage,prepage,nextpage,pages,nowPage,nowSize
defaltStr = '<a href='+thisUrl+'?page='
firstpage = defaltStr+'1>Homepage</a>'
lastpage = defaltStr+pagecos+'>Last page</a>'
pages = Request(page)
//If it is on the first page
//Home page, the previous page is not a link
if(pages <= 1){
rs.AbsolutePage = 1;
firstpage = 'Homepage'
prepage = 'previous page'
nextpage = defaltStr+'2>Next page</a>'
//If it is on the last page
//Last page, the next page is not a link
}else if(pages >= pagecos){
rs.AbsolutePage = pagecos;
prepage = defaltStr+(pagecos-1)+'>Previous page</a>'
lastpage = 'last page'
nextpage = 'next page'
}else{
rs.AbsolutePage = pages
prepage = defaltStr+(Number(pages)-1)+'>Previous page</a>'
nextpage = defaltStr+(Number(pages)+1)+'>Next page</a>'
}
}
nowPage = rs.AbsolutePage
nowSize = rs.PageSize
//If it is on the last page and the number of data displayed is not equal to the number of data displayed on each page
//Because the last page cannot be exactly equal to the amount of data displayed on each page every time
//So you need to define an unequal method
if(nowPage >= pagecos && (pagecos*rs.PageSize)%counts != 0){
nowSize = counts%rs.PageSize
}
%>
<table width=100% border=0 cellspacing=0 cellpadding=0 class=userinfo>
<tr>
<td align=center>
<!--Show homepage, previous page-->
<%=firstpage%> <%=prepage%>
Jump to <select onchange=location.href='<%=thisUrl%>?page='+this.value>
<%
//Paging relies on loop display
for(var num=1; num<=pagecos; num++){
if(nowPage == num){
%>
<option value=<%=num%> selected=selected><%=num%></option>
<%
}else{
%>
<option value=<%=num%>><%=num%></option>
<%
}
}
%>
</select> page
<!--Show next page, last page-->
<%=nextpage%> <%=lastpage%>
<!--Display the current page number, total number of pages, total number of records, and the number of data displayed on each page-->
Total <%=nowPage%> / <%=pagecos%> page<%=counts%> / <%=rs.PageSize%> records
</td>
</tr>
<%
//Content is displayed in a loop
for(var i=1;i<=nowSize;i++){
%>
<tr>
<td><span>User IP:</span><%=rs(usip)%></td>
</tr>
<tr>
<td><span>Suggestion:</span><%=rs(us1)%></td>
</tr>
<tr>
<td><span>Submission time:</span><%=rs(usetime)%></td>
</tr>
<%
//The database cursor moves to the next record
rs.MoveNext();
}
%>
</table>
<%
//If the database cursor is not in the database column
}else{
Response.Write(No user information!)
}
//Close database connection
rs.Close()
%>