DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Running Total In PHP

08.08.2008
| 5633 views |
  • submit to reddit
        // output running total
// userID,posts,runningTotal|
// 2,23434,28330|
// 6,3443,4896|
// 1,422,1453|
// 3,344,1031|
// 4,344,687|
// 5,343,343|

$q = mysql_query("select * from `members` order by `posts` DESC");
echo 'userID,posts,runningTotal|<br>';
while($a = mysql_fetch_row($q)){
echo "$a[0],$a[1],$total|<br>";
$total = $total - $a[1];
}