Jump to content

why some of these math-row/sum count are good? but others are not??


mac007

Recommended Posts

Hello, all:

 

I have several of these type of lines, each of them representing a column, where I simply sum() each column (in this example, these are "return_useave" & "return_success", then I divide that amount by number of rows, and then I multiply by 100 to get a percentage number. It works fine throughout, specially when several rows come up, or if no-rows come up, BUT if only 1 row comes up, and sum is 0, then the "return_usesave" column shows "100%", instead of 0%. Really weird, cause exact same script shows just fine for other the "return_success" column! Seems like it's picking up a 1 in the (sum), but cant see how if sum seems like should be 0... cause if change the value to 1 in the DB, then it becomes 200%!...

 

Appreciate any help!

 

 

This column shows wrong:

 


<?php $select = mysql_query("SELECT SUM(return_usesave) AS monthsum FROM ucn");
$monthSum=mysql_fetch_array($select);
echo number_format($monthSum['monthsum'] / $totalRows_Recordset1*100); ?>

 

But this column shows just fine:

 

<?php $select = mysql_query("SELECT SUM(return_success) AS monthsum FROM ucn");
$monthSum=mysql_fetch_array($select);
echo number_format($monthSum['monthsum'] / $totalRows_Recordset1)*100; ?>

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.