Regular five, summary
Above we introduce the basic concepts of regular expressions, and how to use regular expressions in VBScript and JavaScript, while at the same time giving you a sense of sensibility through some examples. Regular expressions have a wide range of applications and can solve many practical problems for everyone. This article introduces the content is only a few preliminary knowledge, there are many grammatical rules need everyone to continue to learn, in practice to find problems, solve problems. Back to Top
How to implement the paging display of data records (author: Darkman)
How to implement the paging display of data records (1)
Through the GetRows method of the recordset, the paging display of data records can be realized. The following is a complete example:
<%@ Language = VBSCRIPT%>
<% Option Explicit%>
<%
Dim IStart, Ioffset
IStart = Request ("Start")
Ioffset = Request ("Offset")
If not IsNumeric (IStart) or Len (IStart) = 0 Then
IStart = 0
Else
IStart = CInt (IStart)
End If
If not IsNumeric (Ioffset) or Len (ioffset) = 0 Then
Ioffset = 10
Else
Ioffset = Cint (Ioffset)
End If
Response.Write "View" & Ioffset & "records from" & IStart & "Start <BR>"
Dim objconn, objRS
Set objconn = Server.CreateObject ("ADODB. Connection ")
objConn.Open "Provider=SQLOLEDB.1;Data source= (local); Uid=sa;pwd=;initial catalog=pubs"
Set objRS = Server.CreateObject ("ADODB. Recordset ")
Objrs.open "SELECT * from Authors", objconn
Dim Aresults
Aresults = Objrs.getrows
Objrs.close
Set objRS = Nothing
Objconn.close
Set objconn = Nothing
Dim irows, Icols, Irowloop, Icolloop, Istop
irows = UBound (Aresults, 2)
Icols = UBound (aresults, 1)
If irows > (ioffset + iStart) Then
Istop = Ioffset + iStart-1
Else
Istop = irows
End If
For irowloop = IStart to Istop
For icolloop = 0 to Icols
Response.Write Aresults (Icolloop, Irowloop) & ""
Next
Response.Write "<BR>"
Next
Response.Write "<P>"
If IStart > 0 Then
' Show Top 10 connections '
Response.Write "<a href=" "Paging.asp? Start= "& Istart-ioffset & _
"&offset=" & Ioffset & "" "> Before" & Ioffset & "</A>"
End If
If Istop < irows Then
' Show ' after 10 ' connections
Response.Write "<a href=" "Paging.asp? Start= "& Istart+ioffset & _
"&offset=" & Ioffset & "" "> After" & Ioffset & "</A>"
End If
%>
How to implement pagination display of data (2)
Here is another way to display pagination, through the stored procedures of MS SQL. This method does not apply to an Access database.
Let's say that we want to mytable the data in the datasheet, and first write a stored procedure as follows:
CREATE PROCEDURE Sp_pageditems
(
@Page int,
@RecsPerPage int
)
As
--Speed up the table insertion speed
SET NOCOUNT on
--Start record number
DECLARE @RecCount int
SELECT @RecCount = @RecsPerPage * @Page + 1
--Create a temporary table
CREATE TABLE #TempItems
(
ID int IDENTITY,
Name varchar (50),
Price currency
)
--Prepare temporary tables
INSERT into #TempItems (Name, Price)
SELECT Name,price from MyTable
--Find the minimum ID and maximum ID to query
DECLARE @FirstRec int, @LastRec int
SELECT @FirstRec = (@Page-1) * @RecsPerPage
SELECT @LastRec = (@Page * @RecsPerPage + 1)
--Get the actual record and return if there is any data!
SELECT *,
Morerecords =
(
SELECT COUNT (*)
From #TempItems TI
WHERE ti.id >= @LastRec
)
From #TempItems
WHERE ID > @FirstRec and ID < @LastRec
--Restore settings
SET NOCOUNT off
In this stored procedure, we first create a temporary table of all records and add an AutoNumber field ID. In this way, different records have an incremented unique flag.
Depending on the current page number and the number of records per page, you can calculate the minimum and maximum IDs for each page. To get all the records for the current page.
For ease of display, the stored procedure also calculates the Morerecords field as a criterion for displaying the next page.
The program code that utilizes this stored procedure is as follows:
<%
' Show 10 per page
Const Irecordsperpage = 10
Dim currentpage ' current page number
Dim Bollastpage ' on the last page?
If Len (request.querystring ("page") = 0 Then
CurrentPage = 1
Else
CurrentPage = CInt (request.querystring ("page"))
End If
' Get a record of the current page
strSQL = "Sp_pageditems" & CurrentPage & "," & Irecordsperpage
Objrs.open strSQL, objconn
' Judge whether on the last page
If not objrs.eof Then
If CInt (objRS ("Morerecords")) > 0 Then
Bollastpage = False
Else
Bollastpage = True
End If
End If
%>
<P>