Jump to content

Publish "select Sum" Not Working


tomas.hortlax

Recommended Posts

I know...it's very easy.But for me ... not!OKcode:

echo $no3 ;// Print total   $total1 = mysql_query ( "SELECT SUM ('D') FROM databas WHERE A=$no3");   $total2 = mysql_fetch_array ($total1);  $total3 = $total2['SUM(D)'];  echo 'Value on this serie is' . $total3 ;

I have put in "echo $no3;" only to check if there is a value on it. Yes it is.But I dont get anything at $total3. What are I doing wrong?/Tomas

Link to comment
Share on other sites

Try giving the SUM() column an alias and using that. Also, check mysql_num_rows() - are you sure that it is matching any rows? Also, check mysql_error() to see whether your query has an error in it.

  $total1 = mysql_query ( "SELECT SUM('D') AS sum FROM databas WHERE A=$no3");   $total2 = mysql_fetch_array ($total1);  $total3 = $total2['sum'];  echo 'Value on this serie is' . $total3;

Link to comment
Share on other sites

Try giving the SUM() column an alias and using that. Also, check mysql_num_rows() - are you sure that it is matching any rows? Also, check mysql_error() to see whether your query has an error in it.
  $total1 = mysql_query ( "SELECT SUM('D') AS sum FROM databas WHERE A=$no3");   $total2 = mysql_fetch_array ($total1);  $total3 = $total2['sum'];  echo 'Value on this serie is' . $total3;

No error. And Yes. I know it matches a couple of rows.But...I put in this row "echo mysql_num_rows($total1);" and it does not print anything.../Tomas
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...