Ir para conteúdo

POWERED BY:

Arquivado

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

xanburzum

[Resolvido] busca paginada com índice númerico

Recommended Posts

Código completo de busca paginada com índice númerico + navegadores anterior e próximo segue o código abaixo completo

 

<!--Inicio do corpo da busca-->
				<%
'Option Explicit

Const adOpenStatic   = 3
Const adLockReadOnly = 1
Const adCmdText	  = &H0001

Dim CONN_STRING
CONN_STRING = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("dados/goldnews.mdb")

Dim iPageSize
Dim iPageCount
Dim iPageCurrent
Dim strOrderBy
Dim strSQL
Dim objPagingConn
Dim objPagingRS
Dim iRecordsShown
Dim iFieldCount
Dim iRecordCount
Dim LoopRecordCount
Dim pageNum
Dim counter
Dim markShowPage
Dim I, J

'busca
Dim strBusca

'fields declaradas
Dim componente
Dim descricao
Dim part_number
Dim enc
Dim marca
Dim dc
Dim qtde
Dim condicao

busca = Trim(Request.QueryString("busca"))

iPageSize = 300

If Request.QueryString("page") = "" Then
	iPageCurrent = 1
Else
	iPageCurrent = CInt(Request.QueryString("page"))
End If

strSQL = "SELECT * from lista WHERE descricao + ' - ' + componente LIKE '%"& busca &"%'order by id asc;"

Set objPagingConn = Server.CreateObject("ADODB.Connection")
objPagingConn.Open CONN_STRING

Set objPagingRS = Server.CreateObject("ADODB.Recordset")
objPagingRS.PageSize = iPageSize
objPagingRS.CacheSize = iPageSize
objPagingRS.Open strSQL, objPagingConn, adOpenStatic, adLockReadOnly, adCmdText

iPageCount = objPagingRS.PageCount
iFieldCount = objPagingRS.Fields.Count
iRecordCount = objPagingRS.RecordCount

If iPageCurrent > iPageCount Then iPageCurrent = iPageCount
If iPageCurrent < 1 Then iPageCurrent = 1

If iPageCount = 0 Then
	Response.Write "Registro nao encontrado!"
Else
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body topmargin="0" leftmargin="5" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0">
<table border="1"  bordercolor=#FFFFFF cellpadding="6" cellspacing="0">

<tr><td></td>
<td style=width:164px; bgcolor=#000000 align="left"><font color=#ffffff face=Arial size=1><b>
COMPONENTE</b></td></font>
<td style=width:140px; bgcolor=#000000 align="left"><font color=#ffffff face=Arial size=1><b>
DESCRIÇÃO</b></td>
<td style=width:152px; bgcolor=#000000 align="left"><font color=#ffffff face=Arial size=1><b>
PART NUMBER</b></td>
<td style=width:38px; bgcolor=#000000 align="left"><font color=#ffffff face=Arial size=1><b>
ENC</b></td>
<td style=width:65px; bgcolor=#000000 align="left"><font color=#ffffff face=Arial size=1><b>
MARCA</b></td>
<td style=width:28px; bgcolor=#000000 align="left"><font color=#ffffff face=Arial size=1><b>
D/C</b></td>
<td style=width:30px; bgcolor=#000000 align="left"><font color=#ffffff face=Arial size=1><b>
QTDE</b></td>
<td style=width:92px; bgcolor=#000000 align="left"><font color=#ffffff face=Arial size=1><b>
CONDIÇÃO</b></td>
</tr>

<%

	objPagingRS.AbsolutePage = iPageCurrent

	
	Do While LoopRecordCount < iPageSize And Not objPagingRS.EOF
				
	 	componente = objPagingRS("componente")
	 	descricao = objPagingRS("descricao")
	 	part_number = objPagingRS("part_number")
	 	enc = objPagingRS("enc")
	 	marca = objPagingRS("marca")
	 	dc = objPagingRS("dc")
	 	qtde = objPagingRS("qtde")
	 	condicao = objPagingRS("condicao")


		 response.write "<tr>"
		 response.write "<td></td>"
		 response.write "<td style=width:164px; bgcolor=#267F00><font color=#ffffff face=Arial size=1>" & componente & "</td></font>"
		 response.write "<td style=width:140px; bgcolor=#267F00><font color=#ffffff face=Arial size=1>" & descricao & "</td></font>"
		 response.write "<td style=width:152px; bgcolor=#267F00><font color=#ffffff face=Arial size=1>" & part_number & "</td></font>"
		 response.write "<td style=width:38px; bgcolor=#267F00><font color=#ffffff face=Arial size=1>" & enc & "</td></font>"
		 response.write "<td style=width:65px; bgcolor=#267F00><font color=#ffffff face=Arial size=1>" & marca & "</td></font>"
		 response.write "<td style=width:28px; bgcolor=#267F00><font color=#ffffff face=Arial size=1>" & dc & "</td></font>"
		 response.write "<td style=width:30px; bgcolor=#267F00><font color=#ffffff face=Arial size=1>" & qtde & "</td></font>"
		 response.write "<td style=width:92px; bgcolor=#267F00><font color=#ffffff face=Arial size=1>" & condicao & "</td></font>"
		 response.write "</tr>"

		
		
		LoopRecordCount = LoopRecordCount + 1
		objPagingRS.MoveNext
	Loop

	objPagingRS.Close
	Set objPagingRS = Nothing
	objPagingConn.Close
	Set objPagingConn = Nothing
End If

iRecordCount = iRecordCount - 1
iFieldCount  = iFieldCount - 1
LoopRecordCount = LoopRecordCount - 1

pageNum = Round(iRecordCount/iPageSize)
If pageNum < (iRecordCount/iPageSize) Then pageNum = pageNum + 1

Response.Write "  <b>"
For counter = 1 To pageNum
	if counter=iPageCurrent then
		Response.Write " <span class=activepage> "
		Response.Write counter
		Response.Write " </span>"
		markShowPage=1
	else
		Response.Write " <a onclick=exitoff() href=busca.asp?busca=" & busca & "&page="
		'href=busca.asp?page="
		Response.Write counter
		Response.Write " class=listingLink>"
		Response.Write counter
		Response.Write "</a>"
	end if
Next
Response.Write "</b>"

Response.Write "  "

Response.Write "<b>"

Response.Write "<a href=busca.asp?busca=" & busca & "&page="
If iPageCurrent = 1 Then
	Response.Write pageNum
else
	Response.Write iPageCurrent-1
end if
Response.Write " class=listingLink>anterior</a>  "
Response.Write "<a href=busca.asp?busca=" & busca & "&page="
If iPageCurrent = pageNum Then
	Response.Write "1"
else
	Response.Write iPageCurrent+1
end if
Response.Write " class=listingLink>proximo</a>"

Response.Write "</b>"

%>
<p>

<style>

body {
font-family: Arial, Helvetica, sans-serif; 
font-size: 12px; 
}

td {
font-family: Arial, Helvetica, sans-serif; 
font-size: 12px; 
}

listingLink { 
font-family: Arial, Helvetica, sans-serif; 
font-size: 12px; 
font-weight: bold; 
color: blue; 
text-decoration:none;
margin-left:0px;
margin-right:0px;
}

a.listingLink:hover {
color:#FF0000; 
}

activepage {
color:#ffffee;
background-color: #000033;
font-weight: bold;
}
</style>
</body>
</table>
</html>
				<!--Fim do corpo da busca-->

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.