No meu banco de dados um único produto precisa ter 3 categorias diferente.
EX: A Super Cola 114 faz parte da categoria 2, 13 0, onde 2 é da linha automotiva, o 13 e da linha de construção civil e ZERO é sem categoria.
Preciso dar o loop exibindo apenas os produtos de uma determinada categoria.
EX: Quando eu clicar na categoria AUTOMOTIVA, exiba todos os produtos da categoria AUTOMOTIVA.
Segue abaixo os comandos que estava usando para uma única categoria.
AQUI EU SELECIONAVA A CATEGORIA DESEJADA
dim busca busca = ("3") Set objRS = Server.CreateObject("ADODB.Recordset") 'acrescentei por causa da paginação SQL = "SELECT * FROM Produtos WHERE CodCategoria LIKE '"&busca&"'" ''%"&busca&"%'" Sem os % busca exata.
AQUI O LOOP EXIBINDO 3 REGISTROS POR COLUNA
<% i = 1 do While Not objRS.EOF AND x < objRS.PageSize x = x + 1 dim foto, foto2, nome nome =objRS("Nome") foto =objRS("Foto") foto2 = "<img src="+"fotos_Produtos/"+foto+" alt="+nome+" width="+"80"+" height="+"80"+">" %> <td> <table width="153" border="0" cellspacing="0" cellpadding="0" bordercolor="#E4FCDA"> <tr> <td width="200" height="100%"><div align="center"><%response.Write(foto2)%></div></td> </tr> <tr> <td width="200" height="60"><div align="center"><a href="Detalhe_produto.asp?id=<%=objRS("Codproduto")%>"><%response.Write(nome)%></a></div></td> </tr> </table> <hr> </td> <% 'Define quantidade de colunas If i = 3 Then 'O "3" Define a quantidade de COLUNAS a ser exibido na tabela i = 0 Response.Write "</TR><TR>" End If %> <% i = i + 1 objRS.MoveNext Loop %>
AGORA PRECISO INCLUIR OS COMANDOS PARA SEPARAR AS CATEGORIAS, JÁ TENTEI ISSO ABAIXO.
SELECIONA TODOS OS PRODUTOS DA TBELA
Set objRS = Server.CreateObject("ADODB.Recordset") 'acrescentei por causa da paginação SQL = "SELECT * FROM Produtos"
AGORA O LOOP...
<% i = 1 do While Not objRS.EOF AND x < objRS.PageSize x = x + 1 dim foto, foto2, nome nome =objRS("Nome") foto =objRS("Foto") foto2 = "<img src="+"fotos_Produtos/"+foto+" alt="+nome+" width="+"80"+" height="+"80"+">" %> <td> <% if objRS("CodCategoria") = 2 then %> <table width="153" border="0" cellspacing="0" cellpadding="0" bordercolor="#E4FCDA"> <tr> <td width="200" height="100%"><div align="center"><%response.Write(foto2)%></div></td> </tr> <tr> <td width="200" height="60"><div align="center"><a href="Detalhe_produto.asp?id=<%=objRS("Codproduto")%>"><%response.Write(nome)%></a></div></td> </tr> </table> <% if objRS("CodCategoria2") = 2 then %> <table width="153" border="0" cellspacing="0" cellpadding="0" bordercolor="#E4FCDA"> <tr> <td width="200" height="100%"><div align="center"><%response.Write(foto2)%></div></td> </tr> <tr> <td width="200" height="60"><div align="center"><a href="Detalhe_produto.asp?id=<%=objRS("Codproduto")%>"><%response.Write(nome)%></a></div></td> </tr> </table> <% if objRS("CodCategoria3") = 2 then %> <table width="153" border="0" cellspacing="0" cellpadding="0" bordercolor="#E4FCDA"> <tr> <td width="200" height="100%"><div align="center"><%response.Write(foto2)%></div></td> </tr> <tr> <td width="200" height="60"><div align="center"><a href="Detalhe_produto.asp?id=<%=objRS("Codproduto")%>"><%response.Write(nome)%></a></div></td> </tr> </table> <hr> </td> <%end if%> <%end if%> <%end if%> <% 'Define quantidade de colunas If i = 3 Then 'O "3" Define a quantidade de COLUNAS a ser exibido na tabela i = 0 Response.Write "</TR><TR>" End If %> <% i = i + 1 objRS.MoveNext Loop %>
Isso não funcionaou direito
Quem poder me ajudar eu agradeço.
Visite o site em questão: www.ecovendas.com
Obrigado
Olá, tudo resolvido
Mantive os comandos originais e alterei apenas a instrução SQL para:
SQL = "SELECT * FROM Produtos WHERE (((Produtos.CodCategoria)=2)) or (((Produtos.CodCategoria2)=2)) or (((Produtos.CodCategoria3)=2)) ORDER BY Produtos.Codproduto"
Até +
Site em questão: www.ecovendas.com