mac007 Posted July 12, 2009 Share Posted July 12, 2009 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; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.