The deficiency of the right and the suggestion of amendment

Source: Internet
Author: User
Tags include servervariables table name


Oh, can enter the essence area? It took me a day.
Two brother Zhang << improve the performance of dynamic pagination in ASP >> I am very inspired by the article, but there are some deficiencies in my thinking.

One is unable to respond to some updates with the information.
Add now is a BBS, then the information updated at any time has
Click on each posting
New post information, these in the two Brother Brother's scheme can not be automatically updated, only users can change the query to use.

Second, the memory used too much, in fact, for a forum, most people still in order to visit, there is no need for everyone a session.

Third, the processing of data is not convenient
It can only be done in array mode, not intuitive, poor readability.


For the above points, I propose the following improvement plan
The use of application can be used to achieve multiple people using the same data
Two only save and retrieve ID number, other data make second select
Three automatically deletes obsolete application to save memory.
Iv. re-import data when adding and deleting data

Other benefits
Oh, you can use the GetString (), the original pagination does not
You can use 1, 3,

The code is as follows

A_page.asp
-----------------------------------------------------------------'
<%
Dim apage_pagesize ' Number of records per page
Dim apage_count ' Total Record count
Dim Apage_pagecount ' Total Pages
Dim apage_pageform ' Jump page with form
Dim apage_pageurl ' Previous Page next page link
Dim apage_timeout ' Expiration Time setting (seconds)

apage_timeout=300 ' Expiration Time set (SEC)
Apage_pagesize=20 '

function apage_bactive (str_name) ' To determine if there is this object and to delete expired objects
Apage_bactive=false
Dim Item, S_temp
For Item=1 to Application.contents.count ' Find out all application
S_temp=application.contents (item)
If IsArray (s_temp) Then
If UBound (s_temp) =3 and s_temp (0) = "Apage" Then
If S_temp (1) =str_name Then
Apage_bactive=true ' requires objects to exist
Else
If DateDiff ("s", S_temp (2), now ()) >apage_timeout then ' deletes its object
Application.contents.remove (item)
End If
End If
End If
End If
Next
End Function?? ' B_inuser

Sub Apage_open (Str_name, str_table, str_id, Str_sqlend) ' open object and compute some data
' Object name, table name,? keyword name, query condition
Dim A1, A_ob
If not apage_bactive (str_name) Then ' a new object if the object does not exist
Apage_load Str_name, Str_table, str_id, Str_sqlend
End If
A1=application (Str_name)
A1 (2) =now ()
Application.Lock
Application (Str_name) =a1
Application.UnLock
A_OB=A1 (3)
Apage_count=ubound (a_ob,2) +1
Apage_pagecount=int (apage_count/apage_pagesize) +1
End Sub ' Apage_open

function Apage_get (str_name, page) ' Gets all ID numbers on this page
Dim a1, A_ob, I_stat, I_end, I1, Str_actionurl, Str_query, str_1, str_2
' The following is to ensure that page is correct
Page=cint (page)
If page <1 then page=1
If page >apage_pagecount then Page=apage_pagecount

' Get the ID number
Apage_get= ""
A1=application (Str_name)
A_OB=A1 (3)
i_stat= (page-1) * apage_pagesize
i_end=page* apage_pagesize-1
If I_end> (apage_count-1) Then
I_end=apage_count-1
End If

For I1=i_stat to I_end
Apage_get=apage_get & A_ob (0,I1) & ","
Next
' Get rid of the extra ', ' number
If Len (apage_get) > 0 Then
Apage_get=left (Apage_get, Len (apage_get)-1)
End If


' The following is the information to get users to change pages
Str_actionurl = "http://" & Request.ServerVariables ("Http_host") & Request.ServerVariables ("SCRIPT_NAME")
Str_query=request.servervariables ("Query_string")
Str_1=split (Str_query, "&")
Str_query= ""
For i1=0 to UBound (str_1)
If left (str_1 (I1), 5) <> "page=" Then
Response.Write Left (str_1 (I1), 5) & "<br>"
Str_query=str_query&str_1 (I1) & "&"
End If
Next
Str_2=str_actionurl & "?" &str_query
If Page>1 Then
Apage_pageurl= "<a href=" &str_2 & "Page=1" & "> Home </a>" & _
"<a href=" &str_2 & "Page=" & (page-1) & "> Pre-page </a>"
Else
Apage_pageurl= "Home Front page"
End If
If Page<apage_pagecount Then
apage_pageurl=apage_pageurl& "<a href=" &str_2 & "Page=" & (page+1) & "> Back Page </a>" & _
"<a href=" &str_2 & "page=" &apage_PageCount& "> Last </a>"
Else
apage_pageurl=apage_pageurl& "Back Page last"
End If
apage_pageform= "<table><form method=get name= ' page ' onsubmit= ' document.location = '" "& Str_2 &" page= "" +this.page.value;return false; > "&_
"<tr><td> go to <input type= ' text ' name= ' page ' value= '" &page& "' > page" &_
"<input type=submit style= ' font-size:9pt ' value=go></table>"

End Function

Sub Apage_load (Str_name, str_table, str_id, Str_sqlend) ' New or re-import an object

Sql= "Select" & str_id & "from" & Str_table & Str_sqlend
Set Rs=conn.execute (SQL)
Dim A2 (3)
A2 (0) = "Apage"
A2 (1) =str_name
A2 (2) =now ()
A2 (3) =rs.getrows ()
Application.Lock
Application (Str_name) =a2
Application.UnLock
End Sub ' apage_load

Sub Apage_update (Str_name, str_table, str_id, str_sqlend) ' Use when updating data
If Apage_bactive (str_name) Then ' If an object exists, re-import the object
Apage_load Str_name, Str_table, str_id, Str_sqlend
End If
End Sub

%>


Attached: test.asp
----------------------------------------------------------------------
<!--#include file= "conn.asp"-->
<!--#include file= "a_page.asp"-->
<%
' Build table
' CREATE TABLE page '
' (page_id int?not null IDENTITY (1, 1),
' Page_value int not NULL,
' class_id int NOT null
')
Sub Add_test ' Add test data
Dim I1 ' As int
For i1=0 to 1000
sql= INSERT INTO page (Page_value, class_id) VALUES ("& I1 &", 1)
Conn.execute SQL
Next
For i1=0 to 1000
sql= INSERT INTO page (Page_value, class_id) VALUES ("& I1 &", 2)
Conn.execute SQL
Next
Apage_update "Test", "page", "page_id", "" "
' Apage_update ' test1 ', ' page ', ' page_id ', ' where class_id=1 '
End Sub ' add_test
' Add_test ' to be added to remove '

Dim str_test
Apage_open "Test", "page", "page_id", "" "
' Apage_open ' test1 ', ' page ', ' page_id ', ' where class_id=1 '
Str_test =apage_get ("Test", Request ("page")
' Str_test= apage_get ("Test1", Request ("page"))
Sql= "select?? * from page where page_id in ("& Str_test &") "
Set Rs=conn.execute (SQL)
Response.Write Response.Write "<table border=1><tr><td>" & Rs.getstring (2,, "<td>", "< Tr><td> ") &" </table> "
' or May
' While not rs.eof
' Response.Write ' <a href=hahafish.asp?id= ' & RS ("page_id") & ">" & RS ("Page_value") & "</a>& Lt;br> "
' Rs.movenext
' Wend


Response.Write Apage_pageurl
Response.Write Apage_pageform
%>




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.