Zoação 2 Denunciar post Postado Junho 30, 2014 Tenho a função SUM e sua lógica inicial, mas não sei como inserir no meu código PHP. Preciso listar alguns dados "somados" e "agrupados". Segue abaixo a lógica inicial de minha função SUM SELECT entregador, naturezacomanda, SUM(valorpedidototal) AS 'lucrobruto' FROM contabilidade GROUP BY entregador, naturezacomanda Obrigado desde já Compartilhar este post Link para o post Compartilhar em outros sites
jgustavo99 85 Denunciar post Postado Junho 30, 2014 Olá! Para inserir essa consulta no PHP: <?php $conexao = mysql_connect('localhost','root',''); // Conexão (Recomendo futuramento usar PDO) $select_db = mysql_select_db('NOME DO BANCO DE DADOS', $conexao); // Seleciona o DB $consulta_sql = mysql_query("SELECT entregador, naturezacomanda, SUM(valorpedidototal) AS 'lucrobruto' FROM contabilidade GROUP BY entregador, naturezacomanda",$conexao); ?> Espero ter Ajudado ;) Compartilhar este post Link para o post Compartilhar em outros sites
Zoação 2 Denunciar post Postado Julho 1, 2014 Olá! Para inserir essa consulta no PHP: <?php $conexao = mysql_connect('localhost','root',''); // Conexão (Recomendo futuramento usar PDO) $select_db = mysql_select_db('NOME DO BANCO DE DADOS', $conexao); // Seleciona o DB $consulta_sql = mysql_query("SELECT entregador, naturezacomanda, SUM(valorpedidototal) AS 'lucrobruto' FROM contabilidade GROUP BY entregador, naturezacomanda",$conexao); ?> Espero ter Ajudado ;) Veja só Gustavo, Ao tentar inserir na minha página PHP que possuía, infelizmente não obtive sucesso. Veja o código abaixo como ficou: <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <head> <style type="text/css"> .auto-style4 { font-family: Verdana, Geneva, Tahoma, sans-serif; text-align: center; font-size: x-small; color: #FFFFFF; border: 1px solid #FFFFFF; background-color: #C0C0C0; } a { color: #FF0000; } a:visited { color: #008000; } </style> <title>Listagem por Critérios</title> </head> <?php $conexao = mysql_connect('LOCALHOST','HOST','KEY'); // Conexão (Recomendo futuramento usar PDO) $select_db = mysql_select_db('DEBASE', $conexao); // Seleciona o DB $consulta_sql = mysql_query("SELECT entregador, naturezacomanda, SUM(valorpedidototal) AS 'lucrobruto' FROM contabilidade GROUP BY entregador, naturezacomanda",$conexao); { ?> <style type="text/css"> .auto-style2 { text-align: center; font-size: medium; font-family: "Arial Black"; } .auto-style15 { font-family: Verdana, Geneva, Tahoma, sans-serif; } .auto-style17 { font-size: xx-small; text-align: center; color: #FFFFFF; background-color: #000000; } .auto-style21 { font-size: xx-small; color: #FFFF00; text-align: center; background-color: #000000; } .auto-style22 { margin-bottom: 9px; background-color: #FFFF00; } .auto-style23 { font-size: large; text-align: center; } .auto-style32 { font-size: xx-large; text-align: center; color: #FFFFFF; background-color: #000000; font-family: "Arial Black"; } .auto-style42 { font-size: x-large; text-align: center; color: #FFFFFF; background-color: #FF0000; } .auto-style44 { border-width: 0; font-family: Verdana, Geneva, Tahoma, sans-serif; text-align: center; font-size: small; background-color: #C0C0C0; } .auto-style45 { font-family: Verdana, Geneva, Tahoma, sans-serif; text-align: center; font-size: x-small; border: 1px solid #FFFFFF; background-color: #000000; color: #FFFFFF; } .auto-style46 { font-family: Verdana, Geneva, Tahoma, sans-serif; text-align: center; font-size: x-small; border: 1px solid #000000; color: #FFFFFF; } .auto-style47 { border-style: solid; border-width: 1px; } .auto-style48 { font-family: Verdana, Geneva, Tahoma, sans-serif; text-align: center; font-size: x-small; border: 2px solid #000000; color: #FFFFFF; } </style> <br> <p class="auto-style2"> <table align="center" cellpadding="0" cellspacing="0" class="auto-style22" style="width: 800"> <tr class="auto-style15"> <td class="auto-style17" style="height: 15">2014</td> </tr> <tr class="auto-style15"> <td class="auto-style23" style="height: 249px; width: 790;"> <table align="center" cellpadding="0" cellspacing="0" style="width: 700"> <tr> <td> <table style="width: 100%"> <tr> <td class="auto-style42" style="height: 35"> </td> </tr> <tr> <td class="auto-style32" style="height: 106px"> endereco.com.br</td> </tr> <tr> <td class="auto-style42" style="height: 35"> </td> </tr> </table> </td> </tr> </table> </td> </tr> <tr class="auto-style15"> <td class="auto-style21" style="height: 15"> hosted zoacao</td> </tr> </table> <br></p> <p class="auto-style2"> </p> <?php exit(); } ?> <table align="center" cellpadding="0" cellspacing="0" style="width: 900" class="auto-style47"> <tr> <td class="auto-style4" style="height: 24; " colspan="7"> </td> </tr> <tr> <td class="auto-style45" style="height: 24; width: 34px"><strong>ID</strong></td> <td class="auto-style45" style="height: 24; width: 82px"><strong>DATA</strong></td> <td class="auto-style45" style="height: 24; width: 81px"><strong>ENTREGADOR</strong></td> <td class="auto-style45" style="height: 24; "><strong>BAIRRO</strong></td> <td class="auto-style45" style="height: 24; width: 330"><strong>VLR PEDIDO</strong></td> <td class="auto-style45" style="height: 24"><strong>VLR ENTREGA</strong></td> <td class="auto-style45" style="height: 24; width: 50;">LUCRO</td> </tr> <?php while ($fila=mysql_fetch_array($rst_pedidos)) { ?> <tr> <td class="auto-style48" style="height: 20; "><?php echo $fila["codigointernocontabilidade"]; ?></td> <td class="auto-style46" style="height: 20; "><?php echo $fila["datapedido"]; ?></td> <td class="auto-style46" style="height: 20; "><?php echo $fila["entregador"]; ?></td> <td class="auto-style46" style="height: 20; "><?php echo $fila["bairroentrega"]; ?></td> <td class="auto-style46" style="height: 20; "><?php echo $fila["naturezacomanda"]; ?></td> <td class="auto-style46" style="height: 20; "><?php echo $fila["valorpedidototal"]; ?></td> <td class="auto-style46" style="height: 20; "><?php echo $fila["valorentregaautomatico"]; ?></td> </tr> <?php } mysql_free_result($rst_pedidos); ?> <tr> <td class="auto-style44" style="height: 20; " colspan="7"> </td> </tr> </table> Agora não é listado nada. Compartilhar este post Link para o post Compartilhar em outros sites
jgustavo99 85 Denunciar post Postado Julho 1, 2014 Olá! Sim ele faz somente um consulta (OK). O que você gostaria de fazer com a consulta SQL (SELECT entregador, naturezacomanda, SUM(valorpedidototal) AS 'lucrobruto' FROM contabilidade GROUP BY entregador, naturezacomanda)? Listar algo? Fico no Aguardo ;) Compartilhar este post Link para o post Compartilhar em outros sites
Marlon Pacheco 132 Denunciar post Postado Julho 1, 2014 Pq esse <?php exit(); } ?> Compartilhar este post Link para o post Compartilhar em outros sites