Consulta em dois registros
Salve salve galera,
Tenho uma dúvida... acredito ser fácil mais to apanhando feio aqui!
Tenhos 3 recordsets em uma página:
Produtos | Comentários | Tema
Como podem deduzir o comentário é sobre os produtos, portanto tenho vários comentários para um só produto, quero ligar o comentário ao produto em questão já que estão em tabelas diferentes no bd (Produtos e Comentarios), no entanto relacionadas (ACCESS). O Campo que se relaciona com ambas é o Código....
Vou postar o código pra ver se alguem me ajuda nessa bronca!
Código:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="Connections/con_fvsj.asp" -->
<%
Dim Produtos
Dim Produtos_cmd
Dim Produtos_numRows
Set Produtos_cmd = Server.CreateObject ("ADODB.Command")
Produtos_cmd.ActiveConnection = MM_con_fvsj_STRING
Produtos_cmd.CommandText = "SELECT * FROM produtos"
Produtos_cmd.Prepared = true
Set Produtos = Produtos_cmd.Execute
Produtos_numRows = 0
%>
<%
Dim tema
Dim tema_cmd
Dim tema_numRows
Set tema_cmd = Server.CreateObject ("ADODB.Command")
tema_cmd.ActiveConnection = MM_con_fvsj_STRING
tema_cmd.CommandText = "SELECT * FROM tema"
tema_cmd.Prepared = true
Set tema = tema_cmd.Execute
tema_numRows = 0
%>
<%
Dim comentarios__MMColParam
comentarios__MMColParam = "1"
If (Application("Código") <> "") Then
comentarios__MMColParam = Application("Código")
End If
%>
<%
Dim comentarios
Dim comentarios_cmd
Dim comentarios_numRows
Set comentarios_cmd = Server.CreateObject ("ADODB.Command")
comentarios_cmd.ActiveConnection = MM_con_fvsj_STRING
comentarios_cmd.CommandText = "SELECT * FROM comentarios WHERE [Código] = ?"
comentarios_cmd.Prepared = true
comentarios_cmd.Parameters.Append comentarios_cmd.CreateParameter("param1", 5, 1, -1, comentarios__MMColParam) ' adDouble
Set comentarios = comentarios_cmd.Execute
comentarios_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index
Repeat1__numRows = 10
Repeat1__index = 0
Produtos_numRows = Produtos_numRows + Repeat1__numRows
%>
<%
' *** Recordset Stats, Move To Record, and Go To Record: declare stats variables
Dim Produtos_total
Dim Produtos_first
Dim Produtos_last
' set the record count
Produtos_total = Produtos.RecordCount
' set the number of rows displayed on this page
If (Produtos_numRows < 0) Then
Produtos_numRows = Produtos_total
Elseif (Produtos_numRows = 0) Then
Produtos_numRows = 1
End If
' set the first and last displayed record
Produtos_first = 1
Produtos_last = Produtos_first + Produtos_numRows - 1
' if we have the correct record count, check the other stats
If (Produtos_total <> -1) Then
If (Produtos_first > Produtos_total) Then
Produtos_first = Produtos_total
End If
If (Produtos_last > Produtos_total) Then
Produtos_last = Produtos_total
End If
If (Produtos_numRows > Produtos_total) Then
Produtos_numRows = Produtos_total
End If
End If
%>
<%
' *** Recordset Stats: if we don't know the record count, manually count them
If (Produtos_total = -1) Then
' count the total records by iterating through the recordset
Produtos_total=0
While (Not Produtos.EOF)
Produtos_total = Produtos_total + 1
Produtos.MoveNext
Wend
' reset the cursor to the beginning
If (Produtos.CursorType > 0) Then
Produtos.MoveFirst
Else
Produtos.Requery
End If
' set the number of rows displayed on this page
If (Produtos_numRows < 0 Or Produtos_numRows > Produtos_total) Then
Produtos_numRows = Produtos_total
End If
' set the first and last displayed record
Produtos_first = 1
Produtos_last = Produtos_first + Produtos_numRows - 1
If (Produtos_first > Produtos_total) Then
Produtos_first = Produtos_total
End If
If (Produtos_last > Produtos_total) Then
Produtos_last = Produtos_total
End If
End If
%>
<%
Dim MM_paramName
%>
<%
' *** Move To Record and Go To Record: declare variables
Dim MM_rs
Dim MM_rsCount
Dim MM_size
Dim MM_uniqueCol
Dim MM_offset
Dim MM_atTotal
Dim MM_paramIsDefined
Dim MM_param
Dim MM_index
Set MM_rs = Produtos
MM_rsCount = Produtos_total
MM_size = Produtos_numRows
MM_uniqueCol = ""
MM_paramName = ""
MM_offset = 0
MM_atTotal = false
MM_paramIsDefined = false
If (MM_paramName <> "") Then
MM_paramIsDefined = (Request.QueryString(MM_paramName) <> "")
End If
%>
<%
' *** Move To Record: handle 'index' or 'offset' parameter
if (Not MM_paramIsDefined And MM_rsCount <> 0) then
' use index parameter if defined, otherwise use offset parameter
MM_param = Request.QueryString("index")
If (MM_param = "") Then
MM_param = Request.QueryString("offset")
End If
If (MM_param <> "") Then
MM_offset = Int(MM_param)
End If
' if we have a record count, check if we are past the end of the recordset
If (MM_rsCount <> -1) Then
If (MM_offset >= MM_rsCount Or MM_offset = -1) Then ' past end or move last
If ((MM_rsCount Mod MM_size) > 0) Then ' last page not a full repeat region
MM_offset = MM_rsCount - (MM_rsCount Mod MM_size)
Else
MM_offset = MM_rsCount - MM_size
End If
End If
End If
' move the cursor to the selected record
MM_index = 0
While ((Not MM_rs.EOF) And (MM_index < MM_offset Or MM_offset = -1))
MM_rs.MoveNext
MM_index = MM_index + 1
Wend
If (MM_rs.EOF) Then
MM_offset = MM_index ' set MM_offset to the last possible record
End If
End If
%>
<%
' *** Move To Record: if we dont know the record count, check the display range
If (MM_rsCount = -1) Then
' walk to the end of the display range for this page
MM_index = MM_offset
While (Not MM_rs.EOF And (MM_size < 0 Or MM_index < MM_offset + MM_size))
MM_rs.MoveNext
MM_index = MM_index + 1
Wend
' if we walked off the end of the recordset, set MM_rsCount and MM_size
If (MM_rs.EOF) Then
MM_rsCount = MM_index
If (MM_size < 0 Or MM_size > MM_rsCount) Then
MM_size = MM_rsCount
End If
End If
' if we walked off the end, set the offset based on page size
If (MM_rs.EOF And Not MM_paramIsDefined) Then
If (MM_offset > MM_rsCount - MM_size Or MM_offset = -1) Then
If ((MM_rsCount Mod MM_size) > 0) Then
MM_offset = MM_rsCount - (MM_rsCount Mod MM_size)
Else
MM_offset = MM_rsCount - MM_size
End If
End If
End If
' reset the cursor to the beginning
If (MM_rs.CursorType > 0) Then
MM_rs.MoveFirst
Else
MM_rs.Requery
End If
' move the cursor to the selected record
MM_index = 0
While (Not MM_rs.EOF And MM_index < MM_offset)
MM_rs.MoveNext
MM_index = MM_index + 1
Wend
End If
%>
<%
' *** Move To Record: update recordset stats
' set the first and last displayed record
Produtos_first = MM_offset + 1
Produtos_last = MM_offset + MM_size
If (MM_rsCount <> -1) Then
If (Produtos_first > MM_rsCount) Then
Produtos_first = MM_rsCount
End If
If (Produtos_last > MM_rsCount) Then
Produtos_last = MM_rsCount
End If
End If
' set the boolean used by hide region to check if we are on the last record
MM_atTotal = (MM_rsCount <> -1 And MM_offset + MM_size >= MM_rsCount)
%>
<%
' *** Go To Record and Move To Record: create strings for maintaining URL and Form parameters
Dim MM_keepNone
Dim MM_keepURL
Dim MM_keepForm
Dim MM_keepBoth
Dim MM_removeList
Dim MM_item
Dim MM_nextItem
' create the list of parameters which should not be maintained
MM_removeList = "&index="
If (MM_paramName <> "") Then
MM_removeList = MM_removeList & "&" & MM_paramName & "="
End If
MM_keepURL=""
MM_keepForm=""
MM_keepBoth=""
MM_keepNone=""
' add the URL parameters to the MM_keepURL string
For Each MM_item In Request.QueryString
MM_nextItem = "&" & MM_item & "="
If (InStr(1,MM_removeList,MM_nextItem,1) = 0) Then
MM_keepURL = MM_keepURL & MM_nextItem & Server.URLencode(Request.QueryString(MM_item))
End If
Next
' add the Form variables to the MM_keepForm string
For Each MM_item In Request.Form
MM_nextItem = "&" & MM_item & "="
If (InStr(1,MM_removeList,MM_nextItem,1) = 0) Then
MM_keepForm = MM_keepForm & MM_nextItem & Server.URLencode(Request.Form(MM_item))
End If
Next
' create the Form + URL string and remove the intial '&' from each of the strings
MM_keepBoth = MM_keepURL & MM_keepForm
If (MM_keepBoth <> "") Then
MM_keepBoth = Right(MM_keepBoth, Len(MM_keepBoth) - 1)
End If
If (MM_keepURL <> "") Then
MM_keepURL = Right(MM_keepURL, Len(MM_keepURL) - 1)
End If
If (MM_keepForm <> "") Then
MM_keepForm = Right(MM_keepForm, Len(MM_keepForm) - 1)
End If
' a utility function used for adding additional parameters to these strings
Function MM_joinChar(firstItem)
If (firstItem <> "") Then
MM_joinChar = "&"
Else
MM_joinChar = ""
End If
End Function
%>
<%
' *** Move To Record: set the strings for the first, last, next, and previous links
Dim MM_keepMove
Dim MM_moveParam
Dim MM_moveFirst
Dim MM_moveLast
Dim MM_moveNext
Dim MM_movePrev
Dim MM_urlStr
Dim MM_paramList
Dim MM_paramIndex
Dim MM_nextParam
MM_keepMove = MM_keepBoth
MM_moveParam = "index"
' if the page has a repeated region, remove 'offset' from the maintained parameters
If (MM_size > 1) Then
MM_moveParam = "offset"
If (MM_keepMove <> "") Then
MM_paramList = Split(MM_keepMove, "&")
MM_keepMove = ""
For MM_paramIndex = 0 To UBound(MM_paramList)
MM_nextParam = Left(MM_paramList(MM_paramIndex), InStr(MM_paramList(MM_paramIndex),"=") - 1)
If (StrComp(MM_nextParam,MM_moveParam,1) <> 0) Then
MM_keepMove = MM_keepMove & "&" & MM_paramList(MM_paramIndex)
End If
Next
If (MM_keepMove <> "") Then
MM_keepMove = Right(MM_keepMove, Len(MM_keepMove) - 1)
End If
End If
End If
' set the strings for the move to links
If (MM_keepMove <> "") Then
MM_keepMove = Server.HTMLEncode(MM_keepMove) & "&"
End If
MM_urlStr = Request.ServerVariables("URL") & "?" & MM_keepMove & MM_moveParam & "="
MM_moveFirst = MM_urlStr & "0"
MM_moveLast = MM_urlStr & "-1"
MM_moveNext = MM_urlStr & CStr(MM_offset + MM_size)
If (MM_offset - MM_size < 0) Then
MM_movePrev = MM_urlStr & "0"
Else
MM_movePrev = MM_urlStr & CStr(MM_offset - MM_size)
End If
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="[http://www.w3.org/1999/xhtml">](http://www.w3.org/1999/xhtml)
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Fábrica de VELAS São João - Nossos produtos</title>
<meta name="description" content="Fábrica de VELAS São João - Nosso portfólio de produtos contemplando VELAS decorativas, aromáticas, artesanais todas produzidas com excelente parafina. Escolha a VELA e entre em contato com nossa equipe comercial para comprar velas em gel, flutuante, de casamento ou de natal. Entregamos para todo o Brasil!" />
<meta name=”keywords” content="aromaticas, arranjos velas, artesanais, castiçais, comercio de velas, comprar vela, fabrica de velas, velas de gel, parafina, formas de vela, modelos de velas, moldes de velas, vela andiroba, vela de aniversario, vela aromatizada, vela aromatica, vela de pascoa, velas decorativa, velas flutuante, velas piscina, velas natal, velas atacado, velas varejo, velas casamento, velas esotericas, velas especiais, velas customizadas, venda de velas">
<link href="css/modelagem.css" rel="stylesheet" type="text/css" />
<style type="text/css"><!--
textarea {
font-size: 14px;
}-->
</style>
</head>
<body>
<div id="conteudo">
<div id="lad_esq"><img src="imagens/velas_decorativas.jpg" alt="Fábrica de Velas São João" width="320" height="552" /></div>
<div id="lad_dir">
<span class="logo"><a href="index.asp"><img src="imagens/fabrica_de_velas.png" alt="Fábrica de Velas São João" width="539" height="77" border="0" class="logo" /></a></span><a href="produtos.asp"><img src="imagens/nossos_produtos.png" alt="nossos produtos" width="700" height="40" border="0" /></a><a href="produtos.asp"><img src="imagens/B1.png" alt="Nossos produtos" width="232" height="66" border="0" /></a><a href="produtos_destaque.asp?tema=semana santa"><img src="imagens/B2.png" alt="produtos em destaque" width="232" height="66" border="0" /></a><a href="nossos_clientes.asp"><img src="imagens/B3.png" alt="nossos clientes" width="232" height="66" border="0" /></a><a href="produtos.asp"><img src="imagens/B3-2.jpg" alt="Nossos produtos" border="0" /></a><a href="produtos_destaque.asp?tema=semana santa"><img src="imagens/B2.2.jpg" alt="produtos decorativos" width="232" height="200" border="0" /></a><a href="nossos_clientes.asp"><img src="imagens/B4-1.jpg" alt="nossos clientes" width="232" height="200" border="0" /></a><a href="produtos_destaque.asp?tema=semana santa"><img src="imagens/b5.png" alt="Produtos esotericos" width="696" height="40" border="0" /></a><img src="imagens/b6.png" alt="semana santa" width="700" height="130" border="0" usemap="#semana_santa" />
<map name="semana_santa" id="semana_santa">
<area shape="rect" coords="222,84,368,104" href="produtos_destaque.asp?tema=semana santa" alt="Semana Santa" />
</map>
</div>
<img src="imagens/menu.png" alt="Menu Velas São João" border="0" usemap="#menu" />
<map name="menu" id="menu">
<area shape="rect" coords="0,1,165,66" href="index.asp" alt="Página Inicial" />
<area shape="rect" coords="167,1,341,68" href="historico.asp" alt="Histórico da Fábrica" />
<area shape="rect" coords="343,1,513,65" href="produtos.asp" alt="Nossos produtos" />
<area shape="rect" coords="515,3,689,62" href="dicas.asp" alt="Dicas de uso das velas" />
<area shape="rect" coords="692,4,862,58" href="depoimentos.asp" alt="Depoimentos dos nossos clientes" />
<area shape="rect" coords="865,5,1017,60" href="contato.asp" alt="Fale conosco" />
</map>
<div id="baix_esq3"><img src="imagens/nossos_produtos2.png" alt="nossos produtos" width="696" height="40" /></div>
<div id="busca_produto"> <br />
<a href="index.asp">Velas São João </a>>Produtos
<br />
<form action="produtos_destaque.asp" method="get" name="busca_produto" id="busca_produto">
<br />
<table width="987" border="0" align="right" cellpadding="2" cellspacing="0">
<tr>
<td width="13%" bgcolor="#FF9900"><img src="imagens/escolha_por_produto.png" width="131" height="51" alt="escolha-por-produto" /></td>
<td width="42%" bgcolor="#FFAA2B">
<p>Escolha por tema:
<label>
<select name="tema" class="combos" id="tema">
<%While (NOT tema.EOF)
%>
<option value="<%=(tema.Fields.Item("tema").Value)%>"><%=(tema.Fields.Item("tema").Value)%></option>
<%
tema.MoveNext()Wend
If (tema.CursorType > 0) Then
tema.MoveFirst
Else
tema.Requery
End If
%>
</select>
</label>
<label>
<input name="Ok" type="submit" class="combos" id="Ok" value="Ok" />
</label>
<br />
<br />
<img src="imagens/download.png" width="13" height="13" alt="download_portfólio" /><a href="downloads/Produtos-Velas-São-Joao.pdf">Download do nosso portfólio de velas e artigos de decoração</a></p>
</td>
<td width="9%" bgcolor="#FF9900"><img src="imagens/busca_tema.png" width="84" height="51" alt="busca-por-tema" /></td>
<td width="42%" bgcolor="#FFAA2B"><label>Busca por tema:
<input name="busca por velas" type="text" class="combos" id="busca por velas" />
</label>
<label>
<input name="localizar2" type="submit" class="combos" id="localizar2" value="Ok" />
<br />
Use como base dias santos. (Ex. Semana Santa e Círio) </label></td>
</tr>
</table>
</form>
</div>
<div id="escolha_tema"></div>
<div id="depoimentos_2">
<%While ((Repeat1__numRows <> 0) AND (NOT Produtos.EOF))
%>
<table width="980" border="0" cellpadding="0" cellspacing="4" class="tabela">
<tr>
<td width="197" height="257" align="left" valign="top" bgcolor="#000000"><img src="imagens/produtos/<%=(Produtos.Fields.Item("imagem1").Value)%>.jpg" alt="VELAS decorativas e artesanais" width="193" height="257"/></h1></td>
<td width="768" align="left" valign="top"><h5><%=(Produtos.Fields.Item("produto").Value)%></strong></h5>
<h1>Tema:</h1> <h6><%=(Produtos.Fields.Item("tema").Value)%></h6>
<h1>Características:</h1><h6><%=(Produtos.Fields.Item("caracteristicas").Value)%></h6>
</h1>
</h2><img src="imagens/B9.png" width="79" height="21" border="0" />
<a href="comentario.asp?<%= Server.HTMLEncode(MM_keepNone) & MM_joinChar(MM_keepNone) & "Código=" & Produtos.Fields.Item("Código").Value %>">
<img src="imagens/comente.png" alt="Faça um comentário sobre esse produto" width="79" height="21" border="0" /></a><br />
<br />
<table width="70%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="5%" align="center" valign="top"><img src="imagens/aspas.png" width="17" height="13" /></td>
<td width="89%" valign="top"><h1>As velas são João proporcionaram-me a oportunidade de desenvolver um excelente trabalho para meu cliente, pois deu aquele tchan que estava faltando na iluminação.</h1></td>
<td width="5%" align="center" valign="top"><img src="imagens/aspas2.png" width="17" height="13" /></td>
</tr>
<tr>
<td align="center" valign="top"> </td>
<td valign="top"><h1>Postado por: Fábio Neves</h1></td>
<td align="center" valign="top"> </td>
</tr>
</table></td>
</tr>
</table>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
Produtos.MoveNext()Wend
%>
</div>
<div id="proxima_pagina">Registro: <%=(Produtos_first)%> de <%=(Produtos_last)%> produtos.<br />
<br />
<a href="<%=MM_movePrev%>">
<% If MM_offset <> 0 Then %>
<img src="imagens/anterior.png" alt="página anterior" width="29" height="17" border="0" />
<% End If ' end MM_offset <> 0 %>
</a><a href="<%=MM_moveNext%>"></a><a href="<%=MM_moveNext%>">
<% If Not MM_atTotal Then %>
<img src="imagens/proxima.png" alt="próxima página" width="29" height="17" border="0" />
<% End If ' end Not MM_atTotal %>
</a></div>
<div id="contato_2"><img src="imagens/siga-me2.png" width="586" height="68" border="0" usemap="#menu2" />
<map name="menu2" id="menu2">
<area shape="rect" coords="118,10,211,56" href="[http://twitter.com/velassaojoao"](http://twitter.com/velassaojoao) target="_blank" alt="Siga-me no Twitter" />
<area shape="rect" coords="217,10,281,56" href="[http://www.orkut.com.br/Main#Profile.aspx?origin=is&uid=3386937735147259842"](http://www.orkut.com.br/Main#Profile.aspx?origin=is&uid=3386937735147259842) target="_blank" alt="Orkut - Fábrica de Velas São João " />
<area shape="rect" coords="286,11,393,56" href="[http://www.facebook.com/home.php?#!/profile.php?id=100000183551878"](http://www.facebook.com/home.php?#!/profile.php?id=100000183551878) target="_blank" alt="Facebook - Fábrica de Velas São João" />
<area shape="rect" coords="402,11,497,56" href="[http://maps.google.com.br/maps/place?hl=pt&georestrict=input_srcid%3A30c4f413a561484a"](http://maps.google.com.br/maps/place?hl=pt&georestrict=input_srcid%3A30c4f413a561484a) target="_blank" alt="Google Maps - Fábrica de Velas São João" />
</map>
</div>
<div id="final">
<table width="1010" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><h3><strong>Conteúdo Fábrica de Velas São João:</strong> <a href="historico.asp">Nossa História</a>| <a href="produtos.asp">Produtos</a> | <a href="dicas.asp">Dicas</a> | <a href="semana_santa.asp">Novidades</a> | <a href="parcerias.asp">Parceiros </a><br />
© 2009 Fábrica de Velas São João - Velas e artigos de decoração e presentes. Todos os direitos reservados.<br />
Rua Doutor Assis, 52 - Cidade Velha - Belém - Pará - Telefone (91) 3241-5135</h3>
</h3></td>
</tr>
</table>
</div>
</div>
</body>
</html><%
Produtos.Close()
Set Produtos = Nothing
%>
<%
tema.Close()
Set tema = Nothing
%>
<%
comentarios.Close()
Set comentarios = Nothing
%>
Discussão (1)
Carregando comentários...