Jump to content
Fórum Script Brasil
  • 0
Sign in to follow this  
Guest Vagner Cecílio

Somar Valores Mysql

Question

Guest Vagner Cecílio

:unsure:

Caros amigos.

Tenho uma tenho uma tabela MySQL com a coluna float "preço"...

Como é que eu faço para somar e passar o total do valor "preço"???

alguém pode me socorrer???

Share this post


Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 0

você pode pesquisar todos os dados da tabela e depois somar:

$sql="SELECT preço FROM NOME_TABELA";

$pesquisa= mysql_query($sql);

$total=0;

while($linha=mysql_fetch_array($pesquisa)){

$valor="$linha[preço]";

$total=$total+$valor;

}

Isso se eu entendi certo... :lol:

Share this post


Link to post
Share on other sites
  • 0

isso da pra fazer so com sql

$SQL = "SELECT SUM(preço) as total
FROM Tabela";

$row= mysql_fetch_array($SQL);

$valor = $row[total];

Share this post


Link to post
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.

Guest
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.

Sign in to follow this  



  • Forum Statistics

    • Total Topics
      148486
    • Total Posts
      644145
×
×
  • Create New...