欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

ASP文章系統(tǒng)解決方案實現(xiàn)上一頁下一頁

 更新時間:2007年01月03日 00:00:00   作者:  

復制代碼 代碼如下:

寫的不錯哦,我在網(wǎng)站上也是這么用的,不過沒這個好,那個表里有1百多萬數(shù)據(jù),查一下就出來幾萬。只能這樣搞。

順便貼一個:學習一下:
---------------------------------
一種理論上最快的Web數(shù)據(jù)庫分頁方法  

來自:新聞中心 
點擊:2 加入時間:2002-11-22 15:53:41  
  上篇我們談到了關(guān)于數(shù)據(jù)庫傳統(tǒng)的三種分頁方法和他們的利弊,并且提出了一種理論上最佳的分頁方法,本篇我們就來詳細說說這種最佳的分頁方法。 

一:構(gòu)思。 
在設計Web數(shù)據(jù)庫時,如果我們要編歷每一條紀錄,那么只有采取分頁模式才可以使Web數(shù)據(jù)庫盡快,盡好的呈現(xiàn)給終端用戶,也不會因為8秒原則而使用戶失去瀏覽該頁的興趣。但是即使采取分頁的辦法,當出現(xiàn)多紀錄的數(shù)據(jù)庫時,也難免會使我們的用戶感到翻頁時速度太慢。就如同我的上篇文章說的那樣,幾乎上一片文章的三種分頁方法都有一些缺陷。那么,我們?nèi)绾巫龅侥茏寯?shù)據(jù)庫每次就取我們需要的紀錄,這個很好實現(xiàn),有游標返回多個紀錄集就可以實現(xiàn),但是如果讓數(shù)據(jù)庫的一端不會因為要剛好檢索一頁的紀錄而大耗資源就很難了。最后,經(jīng)過我的不斷改寫程序與測試,終于編寫出了我認為理論上最快的Web數(shù)據(jù)庫分頁方法。 

二:具體實現(xiàn)的存儲過程。 
我們結(jié)合一個BBS問題來談談這種方法。如何讓一個BBS每次每頁只現(xiàn)實需要的一頁紀錄呢?而我們需要提供給數(shù)據(jù)庫有那些參數(shù)呢?可能會有以下參數(shù)。 
第一:就是我們需要的當前的頁數(shù)。 
第二:當前定義的每一頁的紀錄集數(shù)目。這樣你就可以根據(jù)需要在頁面程序中修改每一頁的紀錄數(shù)。當然,如果你不考慮程序的可擴展性,你也可以在數(shù)據(jù)庫里直接規(guī)定每一頁有N條紀錄即可。 
第三:一個輸出參數(shù):就是從數(shù)據(jù)庫里得出當前表中總紀錄數(shù)目的多少。(注意,他不是一個頁的紀錄數(shù)目)他相當于ADO分頁法中的Recordcount。如果你不需要總紀錄數(shù)目可以不用返回他。 
我們來看具體存儲過程的代碼。。。 

CREATE PROCEDURE dbo.PRO_pageview 


@tint_tableid tinyint=1, --這個是BBS的當前版面Id,你可以不用管他。。 
@int_pagenow int=0, 
@int_pagesize int=0, 
@int_recordcount int=0 output --就是得出BBS某個版面的總貼數(shù)。。 



AS 
set nocount on 

declare @int_allid int 
declare @int_beginid int,@int_endid int 
declare @int_pagebegin int, @int_pageend int 

select @int_allid=count(*) from tab_discuss where tint_level=0 and tint_tableid=@tint_tableid 
select @int_recordcount=@int_allid --得出該版面的總貼數(shù) 

declare cro_fastread cursor scroll 
for select int_id from tab_discuss where tint_level=0 and tint_tableid=@tint_tableid order by int_id desc --這里定義游標操作,但是不用臨時紀錄集,而且游標也不需要全部遍歷所有紀錄集。 

open cro_fastread --打開游標 
select @int_beginid=(@int_pagenow-1)*@int_pagesize+1 得出該頁的第一個紀錄Id 
select @int_endid = @int_beginid+@int_pagesize-1 得出該頁的最后一個紀錄的Id 

fetch absolute @int_beginid from cro_fastread into @int_pagebegin 將他的Id傳給一個變量該頁開始的Id 
if @int_endid>@int_allid --這里要注意,如果某一頁不足固定頁數(shù)的紀錄時。如只有一頁紀錄,而且紀錄少于我們定義的數(shù)目?;蛘呤亲詈笠豁摃r。。。 
fetch last from cro_fastread into @int_pageend --直接將游標絕對定位到最后一條紀錄,得出他的id號來。。。 
else 
fetch absolute @int_endid from cro_fastread into @int_pageend 

select int_id,tint_level,tint_children,var_face,var_subject,datalength(txt_content) as int_len,sint_hits,var_url,var_image,var_user,dat_time,tint_tableid,bit_kernul from tab_discuss where tint_tableid=@tint_tableid and int_rootid between @int_pageend and @int_pagebegin order by int_rootid desc,num_order desc --我們就可以利用該頁的第一個id和最后一個id得出中間的id來。。。。(注意。我們這個BBS的數(shù)性結(jié)構(gòu)用了一種很巧妙的算法,就是用一個orderNum浮點數(shù)即可完成排序。。。) 

--開始清場。。。 
close cro_fastread 
deallocate cro_fastread 

return 

我們再看看Asp頁面里的程序操作。。。 

pagenow=cint(request("pagenow")) --當前的頁面。 

if pagenow<=0 then pagenow=1 
pagesize=10 

set cmd=server.CreateObject("adodb.command") 
cmd.ActiveConnection=strconn 
cmd.CommandType=4 
cmd.CommandText="pro_pageview" 

cmd.Parameters.Append cmd.CreateParameter("tint_tableid",adInteger,adParamInput,,tint_tableid) 
cmd.Parameters.Append cmd.CreateParameter("int_pagenow",adInteger,adParamInput,,pagenow) 
cmd.Parameters.Append cmd.CreateParameter("int_pagesize",adInteger,adParamInput,,pagesize) 
cmd.Parameters.Append cmd.CreateParameter("int_recordcount",adInteger,adParamOutput) 

set rs=cmd.Execute 
if rs.eof then 
Response.Write "目前已超過了紀錄個數(shù)或紀錄集為空!" 
Response.End 
end if 

dim arrRs 
arrRs=rs.getrows '可以利用getRows將紀錄集迅速保存到一個二維的數(shù)組中來提高速度。 

recordcount=cmd.Parameters("int_recordcount") 
'注意,當紀錄不足以剛好整除單位頁紀錄時,我們也要將其定義為一頁,如紀錄數(shù)目為2頁多一個紀錄,此時我們的頁數(shù)也要為3頁紀錄。 
if (recordcount mod pagesize)=0 then 
pagecount=recordcount\pagesize 
else 
pagecount=recordcount\pagesize+1 
end if 

<--分頁開始 --> 
<!-- #include file="include\tablepage.asp" -->固定的分頁函數(shù),其實無非是pagenow+1或pagenow-1,pagenow,pagecount 
<!--分頁結(jié)束--> 

<div align="left" class="pblank" > 
<% 
'---------顯示樹性結(jié)構(gòu)!------------- 
level=0 
Response.Write "<ul>" 
for i=0 to ubound(arrRs,2) 
if arrRs(1,i)>level then 
Response.Write "<ul>" 
end if 
if arrRs(1,i)<level then 
for j=arrRs(1,i) to level-1 
Response.Write "</ul>" 
next 
end if 
int_size=arrRs(5,i) 
if int_size=0 then 
str_size=" <

相關(guān)文章

最新評論