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; ?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • 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.