ASP + Oracle Paging

Source: Internet
Author: User

 
Pagesize: the number of records displayed on each page.
Pagecount: the system automatically calculates the total number of pages based on the user-defined pagesize and the total number of records in the table.
Recordcount: Total number of records in the table.
Absolutepage: indicates the current page number. If the attribute absolutepage is set to 3, the current record is moved to 3rd (that is, 1st records) on page 1 ).

After knowing that recordset has these attributes, I believe that it is very easy to display records by page.
Open the database and table, set pagesize and absolutepage, and output the recorded data to the browser.
It is true that access or SQL Server is used as a database, because both databases support the recordset attributes for paging.
Compared with access or SQL Server, Oracle databases provide better security and provide superior performance when the data volume is large,
However, Oracle does not support these paging attributes. This article introduces a method to display ORACLE data records by page using ASP,
This allows oracle users to easily display records on pages. II. Implementation Process Analysis

<%
SQL = "select * from data"
Set conn = server. Createobject ("ADODB. Connection ")
CNN. Open "DSN = servername; uid = user; Pwd = password ;"
Set rs = server. Createobject ("ADODB. recordset ")
Rs. cursortype = 3
Rs. locktype = 3
Rs. Open SQL, Conn // exit if there is no record
If Rs. EOF then
Response. End
End if
%>

// The following table header is displayed:
<P align = "center"> personal data table <br> </P>
<Div align = "center">
<Center>
<Table border = "1" width = "560" cellspacing = "0" cellpadding = "0">
<Tr>
<TD width = "140" align = "center"> NO. </TD>
<TD width = "140" align = "center"> name </TD>
<TD width = "140" align = "center"> telephone </TD> <TD width = "140" align = "center"> email </TD>
</Tr>
<%
Recordsperpage = 10 // you can specify 10 records for each page.
Currentpagenumber = 0 // set the current page number to 0
Index = 1 // set the record number to 1
// If the current page number parameter is not blank, convert the type to a long integer and call this parameter
If request. querystring ("currentpagenumber") <> "then
Currentpagenumber = clng (Request ("currentpagenumber "))
End if
// Because the marker page starts from 0, you need to reduce the parameter by 1.
Currentpagenumber = CurrentPageNumber-1
// Calculate the total number of records below
Totalrrecord = 0
While (not Rs. EOF)
Rs. movenext
Totalrecord = totalrecord 1
Wend
// Calculate the total number of pages totalpagenumber
If (totalrecord mod recordsperpage) = 0 then
Totalpagenumber = (totalrecord/recordsperpage)
Else
Totalpagenumber = (totalrecord/recordsperpage) 1)
End if
// If the input page number parameter is smaller than 0, the homepage is displayed.
If currentpagenumber <0 then
Currentpagenumber = 0
End if
// If the input page number parameter is greater than the total page number minus 1, The last page is displayed.
If currentpagenumber> (TotalPageNumber-1) then
Currentpagenumber = (TotalPageNumber-1)
End if
Rs. movefirst // record pointer returned to the first record
// Let the record pointer go over the record before the input page number and go to the first record on the current page
Passnumber = currentpagenumber * recordsperpage
For I = 0 to passnumber-1
Rs. movenext
Next
Index = passnumber 1
Number = 1 // number indicates the counter.
// The table content on the current page is shown below
While (not Rs. EOF) and (number <= recordsperpage)
%>
<Tr>
<TD width = "140" align = "center"> <% response. Write (INDEX) %> </TD> // number
<TD width = "140" align = "center"> <% response. Write RS ("name") %> </TD> // name
<TD width = "140" align = "center"> <% response. Write RS ("telephone") %> </TD> // call
<TD width = "140" align = "center"> <% response. Write RS ("email") %> </TD> // email
</Tr>
<%
Rs. movenext
Index = index 1 // Add 1
Number = Number 1 // Add 1 to the counter
Wend
Rs. Close
%>
</Table>
</Center>
</Div>
</Html>
// The following form implements page number navigation
<% Pagename = "display. asp" %>
<Form action = <% = pagename %> method = get>
<%
If currentpagenumber <> 0 then
%>
<A href = <% = pagename %>? Currentpagenumber = 1> page 1 </a>
<A href = <% = pagename %>? Currentpagenumber = <% = (currentpagenumber) %> previous page </a>
<%
End if
If currentpagenumber <> (totalpagenumber-1) then
%>
<A href = <% = pagename %>? Currentpagenumber = <% = (currentpagenumber 2) %> next page </a>
<A href = <% = pagename %>? Currentpagenumber = <% = (totalpagenumber) %> last page </a>
<%
End if
%>
Input page number: <input type = text name = currentpagenumber> the page is currently in the <% = (currentpagenumber 1) %> page/total <% = totalpagenumber %> page

 

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.