imarockstar Posted August 12, 2009 Share Posted August 12, 2009 I need to add up a bunch of rows that i have done some math to .... not sure how to do that ... first here is my code : <?php $sql = 'SELECT da._group, da.weight, SUM(da.desa_answer) AS total,(SELECT des.maxscore FROM des WHERE des._group = da._group LIMIT 1 ) as maxscore FROM `des_answers` as da GROUP BY da._group'; $result = mysql_query($sql); while($row = mysql_fetch_assoc($result)) { $maxscorevalue = $row['total'] / $row['maxscore']; $maxscorevalue = $maxscorevalue * 100; $maxscorevalue = round($maxscorevalue); $maxscorepoints = $maxscorevalue * $row['weight']; $totalmaxscorepoints = ''; $qcount = mysql_num_rows($result); $qcount = $qcount * $row['weight']; ?> <div class='group'><?=print_r($row['_group'], true);?></div> <div class='group'><?=print_r($row['weight'], true);?></div> <div class='valuesum'><?=print_r($row['total'], true);?></div> <div class='valuesum'><?=print_r($row['maxscore'], true);?></div> <div class='group'><?=$maxscorevalue;?>%</div> <div class='group'><?=$maxscorepoints;?></div> <br class="clear"> <?php } ?> <div class='totalholderbottom'> <div class="group viewanswhdr">Totals :</div> <div class="valuesum viewanswhdr"><?=$qcount;?></div> <div class="valuesum viewanswhdr">.</div> <div class="valuesum viewanswhdr">.</div> <div class="valuesum viewanswhdr">.</div> <div class="valuesum viewanswhdr"><?=$totalmaxscorepoints;?></div> </div> <br class="clear"> my problem is that i need to take all the $maxscorepoints and add them together and store that sum in the $totalmaxscorepoints variable, but I am not sure how to do that ... bobby Link to comment https://forums.phpfreaks.com/topic/169958-php-adding-some-rows-and-stuff/ Share on other sites More sharing options...
smerny Posted August 12, 2009 Share Posted August 12, 2009 $totalmaxscorepoints = ''; change that to... $totalmaxscorepoints += $maxscorepoints; Link to comment https://forums.phpfreaks.com/topic/169958-php-adding-some-rows-and-stuff/#findComment-896583 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.