Jump to content
Fórum Script Brasil
  • 0


Paulo Campos 01


Fala, pessoal...

como que eu faço pra somar todos os valores da linha valor abaixo destacada ?

$sql="Select date_format(s.data, '%d/%m/%Y - %H:%i') as data, p.nome as produto, p.valor as valor, r.nome as retirante , s.quantidade, s.obs from saida s

inner join produto p on s.produto=p.id

inner join retirante r on r.id=s.retirante

where s.data between '$datai' and '$dataf' order by data desc";

Valeu, aguardando aqui.

Edited by Paulo Campos 01
Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

2 opções:

Some dentro de um laço

$soma = 0;
$query = mysql_query($sql);
while ($resultado = mysql_fetch_assoc($query) {
  $soma += $resultado['valor'];
echo $soma;
ou faça outra consulta SQL, porém somente com a soma dos valores
$sql="SELECT SUM(p.valor) AS valor FROM saida s
INNER JOIN produto p ON s.produto=p.id
WHERE s.data BETWEEN '$datai' AND '$dataf'";

É mais ou menos isso.

Edited by Massaki
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Forum Statistics

    • Total Topics
    • Total Posts
  • Create New...