Simple and efficient ASP paging program

Source: Internet
Author: User

<%@ language = "vbscript" codepage = 936%>
<%
' =================================================== =======================
Dim Idcount ' Total Number of records
Dim pages ' per page number
Dim Pagec ' Total Pages
Dim page ' Page Number
Dim Pagenc ' Paging per page Number of page numbers =pagenc*2+1
pagenc=2
Dim pagenmax ' Maximum page number of pagination displayed per page
Dim pagenmin ' Minimum page number for pagination per page
Page=clng (Request ("page ")"
Dim Start Program Time
Dim Endt ' End of program
Dim datafrom ' Datasheet Name
datafrom= ' table1 '
Dim conn,rs
Dim Datapa Th ' database path the ID to use on the
Dim sqlid ' Page
Dim myself ' This page address
myself = Request.ServerVariables ("Path_info")
Dim SQL ' SQL statement
Dim taxis ' ordered statement
taxis= ' ORDER by ID ASC '
Dim i ' for looping integers
Start=timer ()
datapath= "Db.mdb"
P Ages=30

' Connect to open a database
Dim db
db= "Db.mdb" defines the database path and name
Set conn = Server.CreateObject ("Adodb.connection")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & Server.MapPath (DB)
If Err.Number <> 0 Then
Response.Write "Database link Error!"
Response.End ()
End If

' Get the total number of records
Sql= "SELECT count (ID) as Idcount from [" & Datafrom & "]"
Set Rs=server.createobject ("Adodb.recordset")
Rs.Open sql,conn,0,1
Idcount=rs ("Idcount") ' Get total number of records

if (idcount>0) then ' if the total number of records = 0, then do not process
if (idcount mod pages=0) Then ' if the total number of records is divided by the number of lines per page, = Total records per page +1
Pagec=int (idcount/pages) ' Get total pages
Else
Pagec=int (idcount/pages) +1 ' Get total pages
End If

' Get the id============================================ you need on this page
' Read the ID value of all the records, because only IDs are so fast
sql= "SELECT ID from [" & Datafrom & "]" & Taxis
Set Rs=server.createobject ("Adodb.recordset")
Rs.Open sql,conn,1,1

rs.pagesize = Pages ' show number of records per page
If page < 1 then page = 1
If page > Pagec then page = Pagec
If PAGEC > 0 Then rs.absolutepage = page

 for i=1 to rs.pagesize
 if rs.eof then exit for 
  if (i=1) then
  &nbs P;SQLID=RS ("id")
  else
   sqlid=sqlid & "," &rs ("id")
  end If
 rs.movenext
 next
  ' Get the ID end required for this page ============================================
End If
%>
<!doctype HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en"
<meta http-equiv= "Content-type" content= "text/html"
<title> Caterpillar Quick Paging charset=gb2312
<link rel= "stylesheet" href= "Page.css" type= "Text/css"
<script language= "JavaScript"
<!--
Function gopage () {
//Caterpillar quick Pagination
//mail:mc@flashado.com
//home page: http://www.flashado.com
//qq : 69862476
//This page for beginners to learn, technical irregularities, but also invites you to amend the
window.location.href= "<%=myself%>?page=" + Page.value;
}
//-->
</script>

<body bgcolor= "#f2f2f2" leftmargin= "0" topmargin= "0" marginwidth= "0" marginheight= "0" >
<table width= "100%" height= "100%" border= "0" cellpadding= "cellspacing=" "0" >
<tr>
&LT;TD valign= "Middle" ><table width= "100%" height= "100%" border= "0" cellpadding= "0" cellspacing= "1" bgcolor= "# CCCCCC ">
<tr>
&LT;TD valign= "Top" bgcolor= "#ffffff" ><br> <table width= "90%" border= "0" align= "center" cellpadding= " 0 "cellspacing=" 0 "class=" ZW ">
<tr>
<td><strong><font color= "#ff6600" > Caterpillar quick Pagination </font></strong></td>
</tr>
</table>
<br>
<table width= "90%" border= "0" align= "center" cellpadding= "3" cellspacing= "1" bgcolor= "CCCCCC" class= "ZW" >
&LT;TR align= "center" bgcolor= "#9fcb07" >
&LT;TD width= "9%" ><strong>ID</strong></td>
&LT;TD width= "37%" ><strong> theme </strong></td>
&LT;TD width= "33%" ><strong> content (display first 20 words) </strong></td>
&LT;TD width= "21%" ><strong> time </strong></td>
</tr>
<%
if (Idcount>0 and sqlid<> "") then ' if the total number of records = 0, it is not processed
' Use in the page to brush the language of the data, only read the data required on this page, so fast
Sql= "SELECT [ID],[AAAA],[BBBB],[CCCC] from [' & Datafrom &] where ID in (" & Sqlid & ")" &taxis
Set Rs=server.createobject ("Adodb.recordset")
Rs.Open sql,conn,0,1

while (not rs.eof) ' fills data to table
%>
<tr bgcolor= "#ffffff" >
&LT;TD align= "center" ><%=rs (0)%></td>
<td><%=rs (1)%></td>
<td><%=rs (2)%></td>
&LT;TD align= "Center" ><%=rs (3)%></td>
</tr>
<%
Rs.movenext
Wend
%>
</table>
<br>
<table width= "90%" border= "0" align= "center" cellpadding= "2" cellspacing= "0" class= "ZW" >
&LT;TR align= "center" >
&LT;TD align= "Left" > Shared <strong><font color= "#ff6600" ><%=idcount%></font></strong > Records, <strong><font color= "#ff6600" &GT;&LT;%=PAGE%&GT;&LT;/FONT&GT;&LT;/STRONG&GT;/&LT;%=PAGEC%&GT; Each page <strong><font color= "#ff6600" ><%=pages%></font></strong> bar. </td>
</tr>
</table>
<table width= "90%" border= "0" align= "center" cellpadding= "2" cellspacing= "0" class= "ZW" >
&LT;TR align= "center" >
&LT;TD align= "Right" >
<%
' Set paging page number start ===============================
Pagenmin=page-pagenc ' calculates page number start value
Pagenmax=page+pagenc ' calculates page number ending value
if (pagenmin<1) then ' if the page number begins with a value less than 1 =1
Pagenmin=1
End If

if (page>1) Then ' Show (first page) if the page number is greater than 1
Response.Write ("<a href=" "& Myself &"? page=1 ' ><font color= ' #000000 ' > first page </font></a> &nbsp; ")
End If
if (pagenmin>1) Then ' Show (more before) if the page number begins with a value greater than 1
Response.Write ("<a href=" "& Myself &"? page= "& Page-(pagenc*2+1) &" ' ><font color= ' #000000 ' > more before </font></a>&nbsp; ")
End If

if (PAGENMAX>PAGEC) then ' if the page number ending value is greater than the total page count = Total pages
Pagenmax=pagec
End If

For i = pagenmin to Pagenmax ' Loop output page number
if (i=page) then
Response.Write ("<font color= ' #ff6600 ' ><strong>" & I & "</strong></font>&nbsp;")
Else
Response.Write ("[&nbsp;<a href=" & Myself & "Page=" & I & "><font color= ' #000000 ' >" & I & "&LT;/FONT&GT;&LT;/A&GT;&AMP;NBSP;] &nbsp; ")
End If
Next
if (PAGENMAX&LT;PAGEC) Then ' Show (after) if the page number end value is less than the total page count
Response.Write ("<a href=" "& Myself &"? page= "& Page+ (pagenc*2+1) &" ' ><font color= ' #000000 ' > More </font></a>&nbsp; ")
End If
if (PAGE&LT;PAGEC) Then ' show (last page) if the page number is less than the total page count
Response.Write ("<a href=" "& Myself &"? page= "& Pagec &" ' ><font color= ' #000000 ' > last page </ font></a>&nbsp; ")
End If
' Set paging page number end ===============================
%>
Go to
<input name= "page" type= "text" value= "<%=page%>" size= "5" > page
<input type= "button" name= "Submit" value= "Jump" onclick= "Gopage ()" ></td>
</tr>
</table>
<%
End If
%>
<br>
<table width= "90%" border= "0" align= "center" cellpadding= "2" cellspacing= "0" class= "ZW" >
<tr>
&LT;TD align= "center" >
<%
Endt=timer ()
Rs.close
Set rs=nothing
Conn.close
Set conn=nothing
%>
<%=formatnumber ((Endt-start) *1000,3)%> Ms <br>
This may be 0 milliseconds, but that's not to say it's really 0. </td>
</tr>
</table>
<br></td>
</tr>
</table></td>
</tr>
</table>
</body>

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.