Ir para conteúdo
Fórum Script Brasil

Bruno Techera

Membros
  • Total de itens

    4
  • Registro em

  • Última visita

Sobre Bruno Techera

  • Data de Nascimento 10/12/1988

Perfil

  • Gender
    Male
  • Location
    Santana do Livramento-RS

Bruno Techera's Achievements

0

Reputação

  1. Muito obrigado, deu certo! O código ficou assim: <!DOCTYPE html PUBLIC "-//W3C// DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Teste</title> </head> <?php include "dbconexao.php"; include "estilo1.css"; $sql="SELECT MAX(livros.preço) AS maior_preco, livros.codigo, livros.nome, livros.id_categoria, categorias.cat_nome"; $sql=$sql . " FROM livros"; $sql=$sql . " INNER JOIN categorias"; $sql=$sql . " ON (livros.id_categoria = categorias.id)"; $sql=$sql . " GROUP BY livros.id_categoria"; $sql=$sql . " ORDER BY maior_preco"; $rs=mysql_query($sql,$conexao); ?> <body> <p>Sentença SQL: <strong><?php print $sql; ?></strong></p> <table> <thead> <td>Código</td> <td>Nome</td> <td>Categoria</td> <td align="right">Preço</td> </thead> <?php while ($reg=mysql_fetch_array($rs)) { $codigo=$reg["codigo"]; $nome=$reg["nome"]; $cat_nome=$reg["cat_nome"]; $preço=$reg["maior_preco"]; ?> <tr> <td><?php print $codigo; ?></td> <td><?php print $nome; ?></td> <td><?php print $cat_nome; ?></td> <td align="right">R$ <?php print number_format($preço,2,',','.'); ?></td> </tr> <?php } ?> </table> </body> </html>
  2. Acho que não me expliquei claramente. Abaixo vou colocar um código que consegui rodar. <!DOCTYPE html PUBLIC "-//W3C// DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Teste</title> </head> <?php include "estilo1.inc"; include "dbconexao.php"; $sql = "SELECT id_categoria, AVG(preço) AS media_preco"; $sql = $sql . " FROM livros"; $sql = $sql . " GROUP BY id_categoria"; //$sql = $sql . " ORDER BY media_preco"; $rs = mysql_query($sql,$conexao); $total_registros = mysql_num_rows($rs); ?> <body> <p>Sentença SQL:<strong><?php print $sql?></strong></p> <p>Total de registros retornados pela consulta:<strong><?php print $total_registros?></strong></p> <table cellspacing="0"> <thead> <tr> <td>Categoria</td> <td align="right">Média de preços</td> </tr> </thead> <?php while ($reg = mysql_fetch_array($rs)) { $id_categoria = $reg["id_categoria"]; $media_preco = $reg["media_preco"]; ?> <tr> <td><?php print $id_categoria; ?></td> <td align="right">R$<?php print number_format($media_preco, 2 , ',' , '.'); ?></td> </tr> <?php } ?> </table> </body> </html> <?php mysql_free_result($rs); mysql_close($conexao); ?> Eu gostaria de que em vez de mostrar somente o código da categoria, mostrasse o nome da categoria de livros. O nome da categoria esta na tabela "categorias" Tabela livros: -id_livros -nome -preço -etc...... -id_categoria (relacionado com a tabela "categorias") Tabela categorias: -id_cat -nome_cat
  3. Entra no "serviços grátis" do script brasil, ali têm scripts de contagem
  4. Tenho uma tabela "Livros" e outra "Categorias" preciso realizar uma consulta SQL de modo que: -Exibir os nomes e preços dos livros com o maior preço de cada categoria <!DOCTYPE html PUBLIC "-//W3C// DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>teste</title> </head> <?php include "estilo1.inc"; include "dbconexao.php"; $sql = "SELECT categoria.cat_nome, MAX(livros.preço) AS maior_preco"; $sql = $sql . " FROM livros"; $sql = $sql . " INNER JOIN catergorias"; $sql = $sql . " ON categorias.id = livros.id_categoria"; $sql = $sql . " GROUP BY categorias.cat_nome"; $sql = $sql . " ORDER BY maior_preco"; $rs = mysql_query($sql,$conexao); ?> <body> <p>Sentença SQL: <strong><?php print $sql;?></strong></p> <table cellspacing="0"> <thead> <tr> <td>Categoria</td> <td align="right">Preço Máximo</td> </tr> </thead> <?php while ($reg = mysql_fetch_array($rs)) { $id_categoria = $reg["cat_nome"]; $maior_preco = $reg["maior_preco"]; ?> <tr> <td><?php print $id_categoria; ?></td> <td align="right">R$<?php print number_format($maior_preco, 2 , ',' , '.'); ?></td> </tr> <?php } ?> </body> </html> Eu consegui fazer a tabela mostrando o id da categoria e seu maior preço, mas quando quero mostrar o nome da categoria e seu maior preço da erro. Agradeço a ajuda.
×
×
  • Criar Novo...