Ir para conteúdo

POWERED BY:

Arquivado

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

xanburzum

Super Paginação

Recommended Posts

Em um banco de dados com esta estrutura:

 

tabela: customerInfo

 

com os seguintes campos:

 

ID - Numeração Automática

CompanyName - Texto

CompanyType - Texto

Fname - Texto

Lname - Texto

Address - Texto

City - Texto

State - Texto

Zip - Texto

Phone - numero

Fax - Texto

 

default.asp

<!--#include file="SuperPaginacao.asp"-->




<html>
 <head>
  <title>SuperPaginacao</title>
 </head>
<body>
<%
ShowRecCount = "Yes" 'Yes or No  (você quer mostrar a coluna contagem registro em sua página?)-Case Sensitive
RecsPerPage = 10  'número de registros a mostrar por página

SQL = "SELECT * FROM [CustomerInfo]" 'instrução SQL real e sim você pode incluir uma cláusula where 
ShowFieldNames = "CompanyName///Fname///Lname///Address///City///State///Zip///Phone///Fax"  'Campos banco de dados  /// 

ShowSearch = "Yes" 
SearchChoices = "CompanyName///Fname///Lname" 
SearchChoicesShow = "Company Name///First Name///Last Name" 

ShowHeaders = "Yes" 
ShowFieldHeaderNames = "Company Name///First Name///Last Name///Address///City///State///Zip///Phone///Fax" '

ShowMoreInfo = "Yes" '
JumpPage = "somepage.asp"   'somepage.asp aqui é onde você quer no link Mais Informações para goto
JumpQuerystring = "x"        'Alguns Variaveis para request.querystring
JumpKey = "ID"	'O campo do banco de identificação (nome deve ser um campo do banco)
MoreInfoText = "More Info"   'O que você quer o link jumpPage texto a dizer

response.write CreatePagination(ShowRecCount,RecsPerPage,SQL,ShowFieldNames,ShowSearch,SearchChoices,SearchChoicesShow,ShowHeaders,ShowFieldHeaderNames,ShowMoreInfo,JumpPage,JumpQuerystring,JumpKey,MoreInfoText)
%>
</body>
</html>

SuperPaginacao.asp

<%
'conexão
	set conn = server.createobject("adodb.connection")
	DSN="DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & server.mappath("test.mdb")
	conn.Open DSN

	'MS SQL Connection String
	'Set Conn = Server.CreateObject("ADODB.Connection")
	'SQLConnectionString = "Provider=SQLOLEDB.1;Server=xxxxxxxxxxxxxxxxxxx;Initial Catalog=xxxxxxxxxxxxxx;User ID=xxxxxxxxxxxxxx;Password=xxxxxxxxxx;Application Name=xxxxxxxxxxxxxx;" 
	'Conn.Open SQLConnectionString




Function CreatePagination(ShowRecCount,RecsPerPage,SQL,ShowFieldNames,ShowSearch,SearchChoices,SearchChoicesShow,ShowHeaders,ShowFieldHeaderNames,ShowMoreInfo,JumpPage,JumpQuerystring,JumpKey,MoreInfoText)
	' records por page
	recordsonpage = RecsPerPage

	' conta todos records
	allrecords = 0
		If ShowSearch = "Yes" Then
		'necessário escrever comandos javascript
		%>
			<script LANGUAGE=Javascript>
			function mSubmit(){
			//document.form.submit();
			//alert(document.form.xwith.value);
			document.location.href='?xwhat='+document.form.xwhat.value+'&xwith='+document.form.xwith.value+'';
			}
			</SCRIPT>
			<body onFocus="form.xwith.focus();">
		<%
		'split the SearchChoices & SearchChoicesShow
			ListSearchChoices = Split(SearchChoices,"///")
			ListSearchChoicesShow = Split(SearchChoicesShow,"///")
		'create drop down
			For i = 0 to Ubound(ListSearchChoices)
				If request.querystring("xwhat") = ListSearchChoices(i) Then
					addselect = " selected"
				Else
					addselect = ""
				End if
				daDropDown = daDropDown & "<option value='"& ListSearchChoices(i) &"' "& addselect &">"& ListSearchChoicesShow(i) &"</option>"
			next
		'add a sql WHERE declaração
			if request.querystring("xwhat") <> "" then
				SearchWhat = request.querystring("xwhat")
				SearchWith = request.querystring("xwith")
			else
				SearchWhat = ListSearchChoices(0)
				SearchWith = "%"
			end If
			If InstrRev(LCase(SQL), "where") <> 0 Then
				xwhere = " and "
			Else
				xwhere = " where "
			End if
			SQL = SQL &" "& xwhere &" "& SearchWhat &" like '"& SearchWith &"%'"
				if SearchWith = "%" then
					SearchWith = ""
				end if
		End if
			set rs = conn.Execute(SQL)
			do until rs.EOF
			  allrecords = allrecords + 1
			  rs.movenext
			loop

	' Se o deslocamento é zero, então a primeira página será carregada
	offset = request.querystring("offset")
	if offset = 0 OR offset = "" then
	  requestrecords = 0
	else
	  requestrecords = requestrecords + offset
	end if

	' abre database
	set rs = conn.Execute(SQL)

	' lê primeiros registros (offset), sem mostrá-los (não pode encontrar outra solução!)
	hiddenrecords = requestrecords
	do until hiddenrecords = 0 OR rs.EOF
	  hiddenrecords = hiddenrecords - 1
	  rs.movenext
	  if rs.EOF then
		lastrecord = 1
	  end if
	Loop
	%>
	<% If ShowSearch = "Yes" then%>
	<form action="?" method="post" Name="form">
	search: <input id="xwith" name="xwith" type="Text" size="" onKeyUp="mSubmit();" value="<%=SearchWith%>" onFocus="if (this.createTextRange) {var r = this.createTextRange(); r.moveStart('character', this.value.length); r.select();}">
	   
	<select name="xwhat" onChange="mSubmit();">
		<%=daDropDown%>
	</select>
	</form>
	<% End If %>
		<table cellspacing="5" cellpadding="5" border="0" width="100%">
		<%
		
		ListShowFieldHeaderNames = Split(ShowFieldHeaderNames,"///")

		If ShowHeaders = "Yes" then	%>
		<tr>
			<% If ShowRecCount = "Yes" Then %>
				<td> </td>
			<% End If %>
		
			<% For i = 0 to Ubound(ListShowFieldHeaderNames) %>
				<td><I><B><FONT SIZE="1" COLOR="#9D9D9D"><U><%=ListShowFieldHeaderNames(i)%></U></FONT></B></I></td>
			<% Next %>

			<% If ShowMoreInfo = "Yes" Then %>
				<td> </td>
			<% End If %>
		</tr>
		<% End If %>

		<%
		' imprime registros na tabela
		showrecords = recordsonpage
		recordcounter = requestrecords
		do until showrecords = 0 OR rs.EOF
		recordcounter = recordcounter + 1

		ListShowFieldNames = Split(ShowFieldNames,"///")

		%>
		

		 <tr onMouseOver="this.style.background='#f0f0f0';" onMouseOut="this.style.background='#ffffff';">

		 <% If ShowRecCount = "Yes" Then %>
		  <td width="5"><FONT SIZE="2"><% = recordcounter %>)</FONT></td>
		 <% End If %>

		  <% For i = 0 to Ubound(ListShowFieldNames) %>
			  <td><FONT SIZE="2"><% = rs(ListShowFieldNames(i)) %></FONT></td>
			<% Next %>

			<% If ShowMoreInfo = "Yes" Then %>
			<td><FONT SIZE="2"><a href='<%=JumpPage%>?<%=JumpQuerystring%>=<%If JumpKey <> "" Then response.write rs(JumpKey) End if%>'><%=MoreInfoText%></a></FONT></td>
			<% End If %>

		 </tr>
		<%
		  showrecords = showrecords - 1
		  rs.movenext
		  if rs.EOF then
			lastrecord = 1
		  end if
		loop
		%>
		</tr><tr>
		<% 'Gerenciar tabela espaçamento corretamente
			xtrafieldcount = 1
			If ShowRecCount = "Yes" Then
				xtrafieldcount = xtrafieldcount + 1
			End If
			If ShowMoreInfo = "Yes" Then
				xtrafieldcount = xtrafieldcount + 1
			End If
			ListShowFieldNames = Split(ShowFieldNames,"///")

		%>
		<td colspan="<%= Ubound(ListShowFieldNames) + xtrafieldcount %>">
		<table cellspacing="5" cellpadding="5" border="0" width="100%">
		 <tr>
		  <td align="center"><% if requestrecords <> 0 then %><a href="?offset=<% = requestrecords - recordsonpage %>&xwhat=<%=request.querystring("xwhat")%>&xwith=<%=request.querystring("xwith")%>"><img src="previous.gif" border="0" alt="Previous Page"></a><% else %><img src="blank.gif" border="0"><% end if %>
			   
			<%
			pagelist = 0
			pagelistcounter = 0
			do until pagelist > allrecords  
			  pagelistcounter = pagelistcounter + 1

			If CDbl(request.querystring("offset")) = CDbl(pagelist) Then %>
			<FONT SIZE="3"><% = pagelistcounter %></FONT>
			<% Else %>
			<FONT SIZE="3"><a href="?offset=<% = pagelist %>&xwhat=<%=request.querystring("xwhat")%>&xwith=<%=request.querystring("xwith")%>"><% = pagelistcounter %></a></FONT>
			<% End if
			  pagelist = pagelist + recordsonpage
			loop
			%>
		   
		<% if lastrecord <> 1 then %><a href="?offset=<% = requestrecords + recordsonpage %>&xwhat=<%=request.querystring("xwhat")%>&xwith=<%=request.querystring("xwith")%>"><img src="next.gif" border="0" alt="Next Page"></a><% else %><img src="blank.gif" border="0"><% end if %></td>
		 </tr>
		</table>

		<%
		' fechar connection
		rs.close
		Conn.close
		%>

<%
End Function
%>

Compartilhar este post


Link para o post
Compartilhar em outros sites

executa ele

Compartilhar este post


Link para o post
Compartilhar em outros sites

imaginou errado, ele mostra algumas opções

execute ele e veja o que faz...

Compartilhar este post


Link para o post
Compartilhar em outros sites

cria ele rapidinho

 

tabela: customerInfo

 

com os seguintes campos:

 

ID - Numeração Automática

CompanyName - Texto

CompanyType - Texto

Fname - Texto

Lname - Texto

Address - Texto

City - Texto

State - Texto

Zip - Texto

Phone - numero

Fax - Texto

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.