asp分页系统

分页程序

asp分页系统'定义分页全局变量
asp分页系统
dim code,mdbsql,Page_size,Totalrec,TotalPage,currentPage
asp分页系统
asp分页系统
'参数处理,并把相应代码插入code(分页)和mdbsql(数据库查询)中
asp分页系统
Sub s_keyword(s_value)
asp分页系统    keyword 
= s_value '建议先对keyword进行处理
asp分页系统
    if keyword<>"" then
asp分页系统        code 
= code &"&keyword="& keyword
asp分页系统        text
=Split(keyword) '分词
asp分页系统
        for each word in text
asp分页系统            mdbsql 
= mdbsql &" and charindex('"&trim(word)&"',hw_area)>0"
asp分页系统        
next
asp分页系统    
end if
asp分页系统
end Sub
asp分页系统
asp分页系统
'sql搜索主程序,页次,查找字段,关键字段(唯一索引),排序字段
asp分页系统
Sub fSql(s_page,s_table,s_str,s_key,s_order,mdbconn)
asp分页系统    
if s_page <> "" and IsNumeric(s_page) then currentPage = cint(s_page) else currentPage=1
asp分页系统    
if mdbsql = "" then mdbsql = "1=1"
asp分页系统    
asp分页系统    Totalrec 
= mdbconn.execute("select count(*) from ["&s_table&"] where "&mdbsql)(0)
asp分页系统    
if Totalrec > 0 then
asp分页系统        TotalPage 
= Totalrec\Page_size
asp分页系统        
If (Totalrec Mod Page_size) Then TotalPage = TotalPage+1
asp分页系统        
If TotalPage < 1 Then TotalPage = 1
asp分页系统        
If currentPage > TotalPage Then currentPage = TotalPage    
asp分页系统        
If TotalPage = 1 then Page_size=Totalrec
asp分页系统
asp分页系统        
if currentPage = 1 then
asp分页系统            mdbsql 
= "select top "&Page_size&" "&s_str&" from ["&s_table&"] where "&mdbsql&" order by "&s_order&" desc"
asp分页系统        
else if s_order <> "" and s_order <> s_key then
asp分页系统            mdbsql 
= "select top "&Page_size&" "&s_str&" from ["&s_table&"] where "&mdbsql&" and "&s_key&" not in (select top "&(currentPage-1)*Page_size&" "&s_key&" from ["&s_table&"] where "&mdbsql&" order by "&s_order&" desc) order by "&s_order&" desc"
asp分页系统        
else
asp分页系统            mdbsql 
= "select top "&Page_size&" "&s_str&" from ["&s_table&"] where "&mdbsql&" and "&s_key&" < (select min ("&s_key&") from (select top "&(currentPage-1)*Page_size&" info_id from ["&s_table&"] where "&mdbsql&" order by "&s_key&" desc) as T) order by "&s_key&" desc"
asp分页系统        
end if
asp分页系统    
end if
asp分页系统
end Sub
asp分页系统
asp分页系统
asp分页系统
'分页显示
asp分页系统
Function show_page()
asp分页系统    temp_page 
= ""
asp分页系统    
If currentPage <> 1 Then temp_page = temp_page & "<a href='?page=1"&code&"' title='第一页'><<-</a>" Else temp_page = temp_page & "<<-"    
asp分页系统    temp_page 
= temp_page & "&nbsp;"
asp分页系统    
If currentPage > 1 Then temp_page = temp_page & "<a href='?page=" & currentPage - 1 &code&"&' title='前一页'><-</a>" Else temp_page = temp_page & "<-"
asp分页系统    temp_page 
= temp_page & "&nbsp;"
asp分页系统    
asp分页系统    PageStart 
= currentPage - 5
asp分页系统    
If PageStart < 1 Then PageStart = 1
asp分页系统    PageEnd 
= PageStart + 10
asp分页系统    
If PageEnd > TotalPage Then PageEnd = TotalPage
asp分页系统    
For Temp = PageStart To PageEnd
asp分页系统        
If Temp = currentPage Then temp_page = temp_page & "[" & Temp & "]&nbsp;" Else temp_page = temp_page & "<a href='?page="&Temp&""&code&"' title='第"&Temp&"页'>"&Temp&"</a>&nbsp;"
asp分页系统    
Next
asp分页系统    
asp分页系统    
If currentPage < TotalPage Then temp_page = temp_page & "<a href='?page=" &currentPage + 1 & ""&code&"' title='下一页'>-></a>" Else temp_page = temp_page & "->"
asp分页系统    temp_page 
= temp_page & "&nbsp;"
asp分页系统    
If currentPage < TotalPage Then temp_page = temp_page & "<a href='?page=" & TotalPage &code&"' title='最后一页'>->></a>" Else temp_page = temp_page & "->>"
asp分页系统    
asp分页系统    temp_page 
= temp_page & "&nbsp;&nbsp;共 "&Totalrec&" 条记录,当前第 "&currentPage&" 页,共 "&TotalPage&" 页&nbsp;"
asp分页系统    
asp分页系统    temp_page 
= temp_page & "&nbsp;&nbsp;到第<input name='gopage' id='gopage' type='text' size='3' maxlength='6' value='"&currentPage&"' />页 <input type='button' value='go' onclick=""location.href='?page='+gopage.value+'"&code&"'"" />"
asp分页系统    
asp分页系统    show_page 
= temp_page & ""
asp分页系统
end Function
asp分页系统
'以上程序放到一个function中



使用前定义好变量

asp分页系统'定义参数全局变量
asp分页系统
dim keyword
asp分页系统
asp分页系统Page_size 
= 20
asp分页系统mdbsql
="flag = 1" '可以先定义固定的搜索条件
asp分页系统

asp分页系统
'函数会根据参数自动调整code和mdbsql
asp分页系统
Call s_keyword(trim(Request("keyword")))
asp分页系统
Call s_sql(trim(Request("page")),"title","id","id")
asp分页系统
'以上代码一般放在程序开头


使用

asp分页系统'内容显示
asp分页系统
if Totalrec > 0 then
asp分页系统    
set rs=server.createobject("adodb.recordset")
asp分页系统    rs.open mdbsql,toconn,
1,1    
asp分页系统    
If rs.bof and rs.Eof Then
asp分页系统        response.Write(
"暂时没有信息")
asp分页系统    
else
asp分页系统        
For Temp_FN = 1 to Page_size
asp分页系统            
If rs.Eof Then Exit For
asp分页系统            response.write rs(
"title")
asp分页系统            rs.movenext
asp分页系统        
next
asp分页系统        response.write show_page() 
'分页显示
asp分页系统
    end if
asp分页系统
else
asp分页系统    response.Write(
"暂时没有信息")
asp分页系统
end if

相关文章: