Jump to content

Publish "select Sum" Not Working


tomas.hortlax
 Share

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...