日期:2014-05-17  浏览次数:20946 次

请教 wangwm(星星火炬-http://jymass.com)
你说的  

Function   page1()
sql= "select   top   1   id,title   from   news   where   id < "&rs( "id ")& "   order   by   id   desc "
Set   rspage1=conn.execute(sql)
If   rspage1.eof   And   rspage1.bof   Then
page1= "没有上一篇 "
Else
page1= " <a   href= " "list1.asp?id= "&rspage1(0)& " " "> "&Trim(rspage1( "title "))& " </a> "
End   If
rspage1.close
Set   rspage1=Nothing
End   Function

Function   page2()
sql= "select   top   1   id,title   from   news   where   id> "&rs( "id ")
Set   rspage2=conn.execute(sql)
If   rspage2.eof   And   rspage2.bof   Then
page2= "没有下一篇 "
Else
page2= " <a   href= " "list1.asp?id= "&rspage2(0)& " " "> "&Trim(rspage2( "title "))& " </a> "
End   If
rspage2.close
Set   rspage2=Nothing
End   Function

优化下会更好我想看看该如何优化,我也是个初学者,希望老师指点指点

------解决方案--------------------
我来说两句。不知道对不对。大家别笑
分页的优化,关键在于你写的那条sql语句。和普通语句不一样的就是,这条语句是你显示多少数据,它就掉多少出来~~~

我用asp.net写过这个分页。。你可以参考一下。这个语句~~
http://hi.baidu.com/kmiaoer/blog/item/69fccafca22bd583b801a07d.html
------解决方案--------------------
<%
Function GetPreNextRs(strField, strTableName, strHref, intCurrID, objConn, PreOrNext, keyField) '参数很好理解,参见调用例子
Dim objRs
Dim strSQL
Dim arrList
Dim strLast
Dim arrField

Set objRS = Server.CreateObject( "ADODB.RecordSet ")
objRS.CursorLocation = 3
arrField = Split(Replace(strField, " ", " "), ", ")

Select Case UCase(PreOrNext)
Case "PREV "
strSQL = "Select Top 1 " & strField & " From " & strTableName & " where " & keyField & " < " & intCurrID & " order by " & keyField & " desc "
Set ObjRS = objConn.Execute(strSQL)
If objRs.Eof And objRs.Bof Then
strLast = "没有上一篇 "
Else
arrList = objRs.GetRows
strLast = " <a href= " & strHref & "? " & arrField(0) & "= " & arrList(0, 0) & "> " & arrList(1, 0) & " </a> "
End If
Case "NEXT "
strSQL = "Select Top 1 " & strField & " From " & strTableName & " where " & keyField & " > " & intCurrID & " order by " & keyField
Set ObjRS = objConn.Execute(strSQL)
If objRs.Eof And objRs.Bof Then
strLast = "没有下一篇 "
Else
arrList = objRs.GetRows
strLast = " <a href= " & strHref & "? " & arrField(0) & "= " & arrList(0, 0) & "> " & arrList(1, 0) & " </a> "
End If
Case Else
strLast = "参数错误 "
End Select
objRS.Close
Set objRS = Nothing
GetPreNextRs = strLast
End function

'调用例子:
strDB = Server.MapPath( "My