Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

dolci

Busca em ASP

Recommended Posts

Pessoal, primeiro desculpa pela extenção do código abaixo.

É o seguinte:

Esse sisteminha de busca que tenho, por ter uma grande quantidade de ítens do Banco de Dados SQL, acaba em Timeout.

 

Microsoft OLE DB Provider for SQL Server error '80040e31'

 

Timeout expired

 

/home/inc_search.asp, line 37

 

 

A paginação é de 30 em 30, sei que tem como a busca somente buscar os 30 resultados da página atual e a cada página buscar mais trinta, mas não sei como fazer. Acho que o meu está buscando todos de uma só vez, e depois paginando.

 

Alguém pode dar uma força?

 

<%

 

Dim mypage, mypagesize

mypage=request.querystring("whichpage")

mypagesize=request("pagesize")

If mypage="" then

mypage=1

end if

If mypagesize="" then

mypagesize=30

end if

 

Dim RS, sql

set RS = Server.CreateObject("ADODB.Recordset")

keyword = request("keyword")

sql = "select NotCod, NotData, NotTitulo,NotRelease "&_

" from wsinoticias where NotRelease like '%" & keyword & "%' order by NotData desc "

RS.Open sql, strConn, adOpenStatic, adLockReadOnly, adCmdText

 

Function DataBarra (v_data)

DataBarra = day(v_data)&"/"& month(v_data)&"/"&year(v_data)&"-"&FormatDateTime(v_data,4)

End Function

 

if NOT RS.EOF then

RS.movefirst

 

RS.pagesize=mypagesize

Dim maxpages, maxpage, maxrecs, howmanyrecs, howmanyfields

Dim close, open, iResultCount, ok

Dim whichpage, all

 

RS.Movefirst

maxpages=cint(RS.pagecount)

maxpage = maxpages

maxrecs=cint(RS.pagesize)

RS.absolutepage=mypage

howmanyrecs=0

howmanyfields=RS.fields.count -1

close = "]"

open = "["

else

close = ""

open = ""

end if

 

if NOT RS.Eof Then

iResultCount = (mypagesize * (mypage - 1)) + 1

else

iResultCount = "0"

end if

 

if iResultCount + 9 > RS.recordcount then

ok = RS.recordcount

else

ok = iResultCount + 9

end if

all = RS.recordcount

 

do UNTIL RS.eof OR howmanyrecs>=maxrecs

 

if NOT RS.eof then

titulo = RS("Nottitulo")

estado = RS("NotRelease")

 

%>

<div align="center">

 

<table width="99%" border="1" cellpadding="2" style="border-collapse: collapse" bordercolor="#111111" bgcolor="<%=cinzinha%>">

 

<tr>

<td width="70%"><font face="Arial" size="1" color="#000000"><%= iResultCount %>.<font size="1" face="Verdana, Arial, Helvetica, sans-serif"><i><%=DataBarra(Rs("notdata"))%></i> - </font><a href="news.asp?cod=<%=Rs("Notcod") %>"><%=titulo %></a></td>

</tr>

 

</table><br></div>

<%

 

iResultCount = iResultCount + 1

end if

RS.Movenext

response.flush

howmanyrecs=howmanyrecs+1

loop

maxrecs = RS.recordcount

%><font face="Verdana"> </font> </font>

</b>

<%

if Not iResultCount = 0 then

 

Dim w2, pad, k2, ref, scriptname, isPrev, isNext, isEnd, counter

Dim nextpage, prevpage, intPageDisp, counterstart, counterend, pagesize2, again

 

pad=""

scriptname=request.servervariables("script_name")

if iResultCount <> "0" Then

response.write "<font size='2' color='black' face='Verdana, Arial,Helvetica, sans-serif'> Mais: "

else

end if

if (mypage mod 10) = 0 then

counterstart = mypage - 9

else

counterstart = mypage - (mypage mod 10) + 1

end if

counterend = counterstart + 9

if counterend > maxpages then counterend = maxpages

Response.Write open

for counter=counterstart to counterend

If counter>=10 then

pad=""

end if

if cstr(counter) <> mypage then

ref="<a href='" & scriptname

ref=ref & "?whichpage=" & counter & "&pagesize=" & mypagesize

ref=ref & "&keyword=" & keyword & "'>" & pad & counter & "</a>"

else

ref="<b>" & pad & counter & "</b>"

end if

response.write ref

if counter <> counterend then response.write " "

next

Response.Write close

' Find out if there should be Backward or Forward Buttons on the table.

intPageDisp = False

if mypage = 1 AND RS.recordcount = 9 then

isPrev = False

isNext = False

isEnd = True

elseif mypage = 1 then

isPrev = False

isNext = True

isEnd = False

elseif mypage > 1 AND ok = RS.recordcount then

isPrev = True

isNext = False

isEnd = True

else

isPrev = True

isNext = True

isEnd = False

End If

if RS.recordcount <= 1 then

isNext = False

else

nextpage = mypage + 1

prevpage = mypage - 1

end if

If isPrev = False AND isNext = True AND isEnd = False then

w2 = "  <strong><a HREF=" & scriptname & "?whichpage=" & nextpage & "&pagesize=" & mypagesize & "&keyword=" & keyword & "><font face=verdana size=1>[Próxima]</font></a></strong>"

k2 = ""

End If

if isPrev = True AND isNext = True AND isEnd = False then

w2 = "  <strong><a HREF=" & scriptname & "?whichpage=" & prevpage & "&pagesize=" & mypagesize & "&keyword=" & keyword & "><font face=verdana size=1>[Anterior]</font></a></strong>"

k2 = "  <strong><a HREF=" & scriptname & "?whichpage=" & nextpage & "&pagesize=" & mypagesize & "&keyword=" & keyword & "><font face=verdana size=1>[Próxima]</font></a></strong>"

end if

if isPrev = True AND isNext = False AND isEnd = True then

w2 = "  <strong><a HREF=" & scriptname & "?whichpage=" & prevpage & "&pagesize=" & mypagesize & "&keyword=" & keyword & "><font face=verdana size=1>[Anterior]</font></a></strong>"

k2 = ""

end if

if isPrev = False AND isNext = False AND isEnd = true then

w2 = ""

k2 = ""

end if

response.write w2 & k2

response.write "" & again

%><% else

 

response.write "<center><br><font face=""verdana"" size=""1"" color=""red"">Nenhum registro foi encontrado para o termo<b> "& request.QueryString("keyword") &".<br></font></b> <font face=""verdana"" size=""1"">Tente novamente, reveja as palavras com acentos e caracteres especiais.</center>"

 

end if

response.write "<br><br><br><br>"

RS.close

set RS=nothing

end if

%>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Para resolver problemas com Timeout, defina ele explicitamente na primeira linha de código:

Server.ScriptTimeout = 100 'valor em segundos, quantos você achar necessário

Mas o ideal seria você tentar melhorar seu script, num todo... Falta formatação (identação) do código e está muito confuso...

 

Por exemplo:

Dim mypage, mypagesizemypage=request.querystring("whichpage")mypagesize=request("pagesize")If mypage="" thenmypage=1end ifIf mypagesize="" thenmypagesize=30end if

Poderia ser, simplificando:

Dim mypage, mypagesizepage = Request.QueryString("page")pageSize = Request("pageSize")If page = "" Then page= 1If pageSize = "" Then pageSize= 30

Evite também prefixos nas variáveis ("my"), elas ficam maiores e piores de ler, e também é interessante você utilizar variáveis que se identifiquem com os requests.

 

Ex: whichpage

whichpage = Request.QueryString("whichpage")

Creio que facilitará o encontro de variáveis e seus valores.

 

Boa sorte!

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.