Olá,
Eu tenho duas tabelas para montar um Menu Dinâmico através de um banco de dados MySQL. As tabelas são: "SESSOES" e "SUBSESSOES", elas estão relacionadas respectivamente pelos campos "id" e "cod_id" no intuito de montar um menu dinâmico em uma página ASP (produtos.asp).
A tabela "SESSOES" tem:
[id]..[sessao]
.1.....Menu 01
.2.....Menu 02
.3.....Menu 03
.4.....Menu 04
A tabela "SUBSESSOES" tem:
[id]..[cod_id]..[subsessao]
.1........1.........Submenu 01
.2........1.........Submenu 02
.3........1.........Submenu 03
.4........2.........Submenu 04
.5........2.........Submenu 05
.6........2.........Submenu 06
.7........3.........Submenu 07
.8........3.........Submenu 08
.9........3.........Submenu 09
.10......4.........Submenu 10
.11......4.........Submenu 11
• O SELECT da busca no BD é: "SELECT * FROM sessoes INNER JOIN subsessoes ON (sessoes.id = subsessoes.cod_id)"
• O Recordset é "RSmenu"
• Dentro da página "produtos.asp" eu tenho um Repeat Region montando o Menu Dinâmico como se segue abaixo:<% Dim Repeat__numRows Dim Repeat__index Repeat__numRows = -1 Repeat__index = 0 RSmenu_numRows = RSmenu_numRows + Repeat__numRows %> <% While ((Repeat__numRows <> 0) AND (NOT RSmenu.EOF)) %> <table> <tr> <td> <b><%=(RSmenu.Fields.Item("sessao").Value)%></b> </td> </tr> <tr> <td> <%=(RSmenu.Fields.Item("subsessao").Value)%> </td> </tr> <tr> <td> <img src="images/linha.png"/> </td> </tr> </table> <% Repeat__index = RRepeat__index+1 Repeat__numRows = Repeat__numRows-1 RSmenu.MoveNext() Wend %>
Esse código acima está me retornando as informações colocando o nome da "sessao" correspondente a cada "subsessao" gerada, como se segue na imagem abaixo:
Porém eu gostaria que o código me retornasse o nome da "sessao" e logo abaixo toda respectiva "subssessao". Ou seja, eu gostaria que o código me retornasse igualzinho a imagem que se segue abaixo:
O quê preciso mudar para o Menu ficar assim?
<------------------------- SOLUÇÃO ENCONTRADA --------------------------->
Hoje eu consegui resolver o problema acima descrito para gerar um Menu Dinâmico a partir de um BD MySQL. É o seguinte: eu utilizei dois SQLs e o Do While/Loop para resolver a questão. O código funcionando corretamente segue abaixo.
1) Utilizei o SQL1 para SETar o RSmenu: "SELECT * FROM sessoes"
2) Utilizei o SQL2 para SETar o RSsubmenu: "SELECT * FROM subsessoes WHERE cod_id ='"&RSmenu("id")&"'"
CODE
<%
SQL1 = "SELECT * FROM sessoes"
Set RSmenu = conexao.execute(SQL1)
...
Do While Not RSmenu.EOF
Response.Write "<tr><td>"
If sessao = RSmenu("sessao") Then
Response.Write "<b>"&RSmenu("sessao")&"</b>"
Else
Response.Write "<a href='#'><b>"&RSmenu("sessao")&"</b></a>"
End If
Response.Write "</td></tr>"
SQL2 = "SELECT * FROM subsessoes WHERE cod_id ='"&RSmenu("id")&"'"
Set RSsubmenu = conexao.execute(SQL2)
If Not RSsubmenu.EOF Then
Do While Not RSsubmenu.EOF
Response.Write "<tr><td>"
Response.Write "<a href='#'>"&RSsubmenu("subsessao")&"</a>"
Response.Write "</td></tr>"
RSsubmenu.MoveNext
Loop
Response.Write "<tr><td><img src='images/linha.gif' width='180' height='1'/></td></tr>"
End If
RSmenu.MoveNext
Loop
%>
Sendo assim o meu Menu Dinâmico agora ficou assim:
Então este tópico agora está resolvido e espero poder ter ajudado!
Mestre!!! Eu fiz! Mais engraçado, pois ele não lista os submenus das cotegorias abaixo:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="Connections/padrao.asp" -->
<%
Dim RSmenu
Dim RSmenu_cmd
Dim RSmenu_numRows
Set RSmenu_cmd = Server.CreateObject ("ADODB.Command")
RSmenu_cmd.ActiveConnection = MM_padrao_STRING
RSmenu_cmd.CommandText = "SELECT * FROM SESSOES"
RSmenu_cmd.Prepared = true
Set RSmenu = RSmenu_cmd.Execute
RSmenu_numRows = 0
Dim RSsubmenu
Dim RSsubmenu_cmd
Dim RSsubmenu_numRows
Set RSsubmenu_cmd = Server.CreateObject ("ADODB.Command")
RSsubmenu_cmd.ActiveConnection = MM_padrao_STRING
RSsubmenu_cmd.CommandText = "SELECT * FROM SUBSESSOES WHERE cod_id = " & RSmenu("id") & " "
Set RSsubmenu = RSsubmenu_cmd.Execute
RSsubmenu_numRows = 0
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.style1 {
font-size: 12px;
font-family: Verdana, Arial, Helvetica, sans-serif;
}
.style3 {font-size: 12px; font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; }
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
-->
</style>
</head>
<body>
<table border=0 cellpadding=0 cellspacing=1 width=200 bgcolor=#F5F5F5>
<%
Do While Not RSmenu.EOF
Response.Write "<table border=0 cellpadding=0 cellspacing=1 width=200 bgcolor=#F5F5F5>"
Response.Write "<tr><td>"
Response.Write "<tr><td>"
If sessao = RSmenu("sessao") Then
Response.Write "<b>"&RSmenu("sessao")&"</b>"
Else
Response.Write "<a href='#'><b>"&RSmenu("sessao")&"</b></a> "
End If
Response.Write "</td></tr>"
If Not RSsubmenu.EOF Then
Do While Not RSsubmenu.EOF
Response.Write "<tr><td>"
Response.Write "<a href='xxxxxx.htm'>"&RSsubmenu("subsessao")&"</a>"
Response.Write "</td></tr>"
RSsubmenu.MoveNext
Loop
Response.Write "<tr><td><img src='images/linha.gif' width='180' height='1'/></td></tr>"
Response.Write "</table>"
End If
RSmenu.MoveNext
Loop
%>
</table>
</body>
</html>
<%
RSmenu.Close()
Set RSmenu = Nothing
%>
<%
RSsubmenu.Close()
Set RSsubmenu = Nothing
%>
Resultado
Padaria
Pão de Sal
Farinha
Pão Doce
Supermercado
Não mostra
Varejão
Não mostra
Afazeres
Não mostra
Internet
Não mostra