Ir para conteúdo

POWERED BY:

Arquivado

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

crisaum

Problemas com select's dependentes na mesma pagina

Recommended Posts

pessoal, to com um probleminha aparentemente simples, mas num consegui encontrar nada na net ... eh o seguinte, estou fazendo uma listagem de um cadastro de usuarios, e nessa listagem tenho 2 campos numericos que se relacionam com outra tabela, criei o primeiro select denominado rs e em cima dele estou pegando dados para fazer mais 2 select's, rsUsuario e rsArea, ambos da mesma tabela mas com valores diferentes (obviamente).

 

o problema esta na listagem, pois ele esta dando time out no script, se eu subir algumas linhas o rsUnidade.movenext ele simplesmente ira exibir o ultimo registro, colocando no ligar correto (pelo meu ponto de vista) ele para de funcionar.

 

eu fiz isso algumas vezes, mas nunca na mesma pagina, essa eh a primeira vez que faço varios select's (dependentes entre si) numa mesma pagina.

 

segue o codigo completo abaixo:

 

<!--#include file="../valida.asp" -->
<!--#include file="../includes/layout/header.asp" -->
<%
id_intranet_menu = "2"

x_id_user = Session("user")
x_user_group = Session("user_group")
x_user_name = Session("n_user")

'query strings
fun_excluir = Request.QueryString("fun_excluir")

' pega nome da ferramenta
pasta_atual_ = pastaAtual()
ferramenta_ = select_Campo("SELECT IM.label FROM intranet_menu IM WHERE IM.url like '%"& pasta_atual_ &"%'","label",SGBD)
id_ferramenta_ = select_Campo("SELECT IM.id_menu FROM intranet_menu IM WHERE IM.url like '%"& pasta_atual_ &"%'","id_menu",SGBD)

' pegar atributos do usuario
x_user_cadastrar = select_Campo("SELECT cadastrar FROM intranet_pagina WHERE (id_group = "& x_user_group &" OR id_usuario = "& x_id_user &") AND id_menu = "& id_ferramenta_ &" ORDER BY id_usuario DESC","cadastrar",SGBD)
x_user_editar = select_Campo("SELECT editar FROM intranet_pagina WHERE (id_group = "& x_user_group &" OR id_usuario = "& x_id_user &") AND id_menu = "& id_ferramenta_ &" ORDER BY id_usuario DESC","editar",SGBD)
x_user_excluir = select_Campo("SELECT excluir FROM intranet_pagina WHERE (id_group = "& x_user_group &" OR id_usuario = "& x_id_user &") AND id_menu = "& id_ferramenta_ &" ORDER BY id_usuario DESC","excluir",SGBD)
x_user_consultar = select_Campo("SELECT consultar FROM intranet_pagina WHERE (id_group = "& x_user_group &" OR id_usuario = "& x_id_user &") AND id_menu = "& id_ferramenta_ &" ORDER BY id_usuario DESC","consultar",SGBD)
x_user_imprimir = select_Campo("SELECT imprimir FROM intranet_pagina WHERE (id_group = "& x_user_group &" OR id_usuario = "& x_id_user &") AND id_menu = "& id_ferramenta_ &" ORDER BY id_usuario DESC","imprimir",SGBD)


dim pres
pres = request.querystring("pres")

if pres = "" then
	pres = session("pres")
end if

if pres = "" then
	pres = "todos"
end if

session("pres") = pres

'****************************************************************************
**************************'

dim db
dim rs
dim rsUnidade
dim rsArea
set db = server.createobject("adodb.connection")
set rs = server.createobject("adodb.recordset")
set rsUnidade = server.createobject("adodb.recordset")
set rsArea = server.createobject("adodb.recordset")

db.open = SGBD
db.cursorlocation = 3

'****************************************************************************
**************************'

dim sqlSelect
dim sqlSelectUnidade
dim sqlSelectArea

	if pres = "todos" then
		sqlSelect = "select idusuario, u_nome, u_sobrenome, u_unidade, u_area from dbo.cad_visitantes order by u_nome asc"
	else
		sqlSelect = "select idusuario, u_nome, u_sobrenome, u_unidade, u_area from dbo.cad_visitantes where u_nome like '"& pres &"%' order by u_nome asc"
	end if

	rs.open sqlSelect, db
	
	unidadeID = rs("u_unidade")
	areaID = rs("u_area")

	sqlSelectUnidade = "select * from dbo.cad_visitantes_filtros where idfiltro = '"& unidadeID &"'"
	rsUnidade.open sqlSelectUnidade, db
	
	if areaID <> "" then
		sqlSelectArea = "select * from dbo.cad_visitantes_filtros where idfiltro = '"& areaID &"'"
		rsArea.open sqlSelectArea, db
	end if

'****************************************************************************
**************************'
%>
<!--#include file="../includes/libs/scripts.js" -->
<title>:: INTRANET SERVICE ::</title>
<link href="../includes/estilo.css" rel="stylesheet" type="text/css">
<body bgcolor="#CCCCCC" topmargin="0">
<script language="javascript">
<!--

var endDestino = "";
	
function linkManager(idusuario, nome, tipo) {

	// definindo o destino
	if(tipo == "conf") {
		endDestino = "cadastro_usuarios_excluir_01.asp?id="+ idusuario;
	} else {
		endDestino = "cadastro_usuarios_alterar_02.asp?id="+ idusuario;
	}
	
	// verificando da onde vem o click
	if(nome != "") {
		
		var ok = confirm('Você realmente deseja excluir o usuário "'+ nome +'"?');
		if(ok) {
			window.location.href = endDestino;
		} else {
			return(false);
		}
		
	} else {
		window.location.href = endDestino;
	}
		
}

//-->
</script>
<table width=779 border=0 align="center" cellpadding=0 cellspacing=0>
  <tr> 
	<td colspan=3> <img src="../images/topo_esquerda.gif" width=195 height=34 alt=""></td>
	<td width="398" align="right" valign="bottom" background="../images/direita_topo.gif"><span class="texto-conteudo">usuário: <strong>
	<% Response.Write x_user_name %>
	</strong></span>	  <strong>	</strong></td>
	<td colspan=2 rowspan="3" bgcolor="303F4F"> <img src="../images/logo_banner_space.gif" width=28 height=132 alt=""></td>
	<td width="158" rowspan="4" valign="top" background="../images/fundo2.gif"> <img src="../images/imagem_intranet.gif" width=158 height=167 alt=""></td>
  </tr>
  <tr> 
	<td colspan=3 align="center" valign="middle" bgcolor="#FFFFFF"><div align="left"><img src="../images/layout/logotipo.jpg"> </div></td>
	<td> <img src="../images/banner.gif" width=398 height=76 alt=""></td>
  </tr>
  <tr> 
	<td height="22" colspan=4 align="right" valign="middle" background="../images/msg_bem_vindo.gif" bgcolor="303F4F"></td>
  </tr>
  <tr> 
	<td width="175" rowspan=3 valign="top" nowrap background="../images/fundo2.gif" bgcolor="#F2F2F2"><!--#include file="../includes/menu_intranet.asp" --></td>
	<td height="35" colspan=5 align="center" valign="middle" background="../images/topo_menu_pri.gif" bgcolor="CAD7E6"><span class="texto-conteudo"><strong>	STORMSYS - SISTEMA INTEGRADO DE SERVIÇOS </strong></span></td>
  </tr>
  <tr> 
	<td width="10" background="../images/borda_esquerda.gif">  </td>
	<td height="430" colspan=3 valign="top" bgcolor="CAD7E6"><table width="100%"  border="0" cellspacing="0" cellpadding="00">
	   <tr>
		 <td class="texto-titulo"><p align="center" class="texto-titulo">
<%

Response.Write ferramenta_

%>
		 </p></td>
	   </tr>
	 </table>
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
	  <tr>
		<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
			  <td align="center" class="textonormal"><table border="0" cellspacing="0" cellpadding="0">
				<tr class="txtTituloInterno">
				  <td> </td>
				  <td class="texto-conteudo">Gerenciador de Usuários </td>
				</tr>
				<tr class="txtTituloInterno">
				  <td width="10"> </td>
				  <td class="texto-conteudo"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
					<tr>
					  <td><div align="center"> <a href="<%=request.servervariables("script_name")%>?pres=todos"><img src="../images/letras/todos.png" width="70" height="13" border="0"></a><br>
							  <a href="<%=request.servervariables("script_name")%>?pres=a"><img src="../images/letras/A.png" width="13" height="13" border="0"></a><a href="<%=request.servervariables("script_name")%>?pres=b"><img src="../images/letras/B.png" width="13" height="13" border="0"></a><a href="<%=request.servervariables("script_name")%>?pres=c"><img src="../images/letras/C.png" width="13" height="13" border="0"></a><a href="<%=request.servervariables("script_name")%>?pres=d"><img src="../images/letras/D.png" width="13" height="13" border="0"></a><a href="<%=request.servervariables("script_name")%>?pres=e"><img src="../images/letras/E.png" width="13" height="13" border="0"></a><a href="<%=request.servervariables("script_name")%>?pres=f"><img src="../images/letras/F.png" width="13" height="13" border="0"></a><a href="<%=request.servervariables("script_name")%>?pres=g"><img src="../images/letras/G.png" width="13" height="13" border="0"></a><a href="<%=request.servervariables("script_name")%>?pres=h"><img src="../images/letras/H.png" width="13" height="13" border="0"></a><a href="<%=request.servervariables("script_name")%>?pres=i"><img src="../images/letras/I.png" width="13" height="13" border="0"></a><a href="<%=request.servervariables("script_name")%>?pres=j"><img src="../images/letras/J.png" width="13" height="13" border="0"></a><a href="<%=request.servervariables("script_name")%>?pres=k"><img src="../images/letras/K.png" width="13" height="13" border="0"></a><a href="<%=request.servervariables("script_name")%>?pres=l"><img src="../images/letras/L.png" width="13" height="13" border="0"></a><a href="<%=request.servervariables("script_name")%>?pres=m"><img src="../images/letras/M.png" width="13" height="13" border="0"></a><a href="<%=request.servervariables("script_name")%>?pres=n"><img src="../images/letras/N.png" width="13" height="13" border="0"></a><a href="<%=request.servervariables("script_name")%>?pres=o"><img src="../images/letras/O.png" width="13" height="13" border="0"></a><a href="<%=request.servervariables("script_name")%>?pres=p"><img src="../images/letras/P.png" width="13" height="13" border="0"></a><a href="<%=request.servervariables("script_name")%>?pres=q"><img src="../images/letras/Q.png" width="13" height="13" border="0"></a><a href="<%=request.servervariables("script_name")%>?pres=r"><img src="../images/letras/R.png" width="13" height="13" border="0"></a><a href="<%=request.servervariables("script_name")%>?pres=s"><img src="../images/letras/S.png" width="13" height="13" border="0"></a><a href="<%=request.servervariables("script_name")%>?pres=t"><img src="../images/letras/T.png" width="13" height="13" border="0"></a><a href="<%=request.servervariables("script_name")%>?pres=u"><img src="../images/letras/U.png" width="13" height="13" border="0"></a><a href="<%=request.servervariables("script_name")%>?pres=v"><img src="../images/letras/V.png" width="13" height="13" border="0"></a><a href="<%=request.servervariables("script_name")%>?pres=w"><img src="../images/letras/W.png" width="13" height="13" border="0"></a><a href="<%=request.servervariables("script_name")%>?pres=x"><img src="../images/letras/X.png" width="13" height="13" border="0"></a><a href="<%=request.servervariables("script_name")%>?pres=y"><img src="../images/letras/Y.png" width="13" height="13" border="0"></a><a href="<%=request.servervariables("script_name")%>?pres=z"><img src="../images/letras/Z.png" width="13" height="13" border="0"></a></div></td>
					</tr>
					<tr>
					  <td> </td>
					</tr>
				  </table></td>
				</tr>
				<tr class="txtTexto">
				  <td valign="top"> </td>
				  <td valign="top"><table border="0" cellpadding="5" cellspacing="0">
					  <tr bgcolor="#000000">
						<td width="15" class="txtLinkBranco"> </td>
						<td width="120" class="txtLinkBranco">Nome</td>
						<td width="120" class="txtLinkBranco">Sobrenome</td>
						<td width="75" class="txtLinkBranco">Unidade</td>
						<td width="75" class="txtLinkBranco">Área</td>
						</tr>
<%
	if rs.eof = false then
	  
	  while not rs.eof = true
	  
		if x = 1 then
			bgclass = "trLinkNormal02"
			x = 0
		else
			bgclass = "trLinkNormal01"
			x = 1
		end if
		
			while not rsUnidade.eof
				unidade = rsUnidade("f_valor")

			'if areaID <> "" then
				while not rsArea.eof
				area = rsArea("f_valor")
			'else
			'	area = ""
			'end if
%>
					  <tr class="<%=bgclass%>" onMouseOut="this.className='<%=bgclass%>'" onMouseOver="this.className='trLinkOver'">
						<td align="center" valign="middle"><img onClick="linkManager('<%=rs("idusuario")%>','<%=rs("u_nome")%>','conf');" src="../../images/layout/btn_excluir.gif" width="10" height="10" border="0"></td>
						<td height="15" onClick="linkManager('<%=rs("idusuario")%>','','');"><%=rs("u_nome")%></td>
						<td onClick="linkManager('<%=rs("idusuario")%>','','');"><%=rs("u_sobrenome")%></td>
						<td onClick="linkManager('<%=rs("idusuario")%>','','');"><%=unidade%></td>
						<td onClick="linkManager('<%=rs("idusuario")%>','','');"><% if area <> "" then %><%=area%><% end if %></td>
						</tr>
					  <%
	rs.movenext
	  rsUnidade.movenext
	  rsArea.movenext
	  
	  wend
	  wend
	  wend
	  
	  else
	  %>
					  <tr class="txtTexto">
						<td height="20" colspan="5" class="texto-conteudo">Nenhum registro encontrado. </td>
					  </tr>
					  <% end if %>
				  </table></td>
				</tr>
				<tr>
				  <td valign="top"> </td>
				  <td height="35" valign="bottom"> </td>
				</tr>
			  </table></td>
			</tr>
		  </table>
		  <br></td>
	  </tr>
	</table>
	<p align="center"> 	 </p></td>
	<td width="10" background="../images/borda_direita.gif">  </td>
	<td rowspan=2 valign="top" background="../images/fundo2.gif" bgcolor="#FFFFFF">  
	</td>
  </tr>
  <tr> 
	<td colspan=5 valign="top"> <img src="../images/borda_baixo.gif" width=446 height=12 alt=""></td>
  </tr>
  <tr> 
	<td colspan=7>
	  <!--#include file="../includes/rodape_intranet.asp" -->
	</td>
  </tr>
  <tr> 
	<td> <img src="../images/spacer.gif" width=175 height=1 alt=""></td>
	<td> <img src="../images/spacer.gif" width=10 height=1 alt=""></td>
	<td width="10"> <img src="../images/spacer.gif" width=10 height=1 alt=""></td>
	<td> <img src="../images/spacer.gif" width=398 height=1 alt=""></td>
	<td width="18"> <img src="../images/spacer.gif" width=18 height=1 alt=""></td>
	<td> <img src="../images/spacer.gif" width=10 height=1 alt=""></td>
	<td> <img src="../images/spacer.gif" width=158 height=1 alt=""></td>
  </tr>
</table>
<%
rs.close()
db.close()
set db = nothing
set rs = nothing
%>

alguem imagina como sair dessa enrascada?

Compartilhar este post


Link para o post
Compartilhar em outros sites

Verifique seus Whiles se possuem o MoveNext. Pode estar ocorrendo Loop infinito em algum ponto.

 

Dica, faça cada SELECT separadamente, o mais "externo" primeiro, quando estiver exibindo tudo corretamente coloque o segundo e depois o terceiro, e sem formatação HTML exagerada, conforme esteja funcionando coloque a formatação.

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.