Cooper94 Posted September 8, 2009 Share Posted September 8, 2009 Is it possible to add the row values? <?php include 'db.php'; $sql = "SELECT * FROM pirerp WHERE status = '2'"; $result = mysql_query ($sql); while ($row = mysql_fetch_array($result)) { $cargo = $row['cargo']; echo $cargo; } ?> I am trying to add the values I can do "+=" but it gives me two values one added and one not. Thank you for your help! Link to comment https://forums.phpfreaks.com/topic/173477-addition-of-rows/ Share on other sites More sharing options...
DavidAM Posted September 8, 2009 Share Posted September 8, 2009 <?php include 'db.php'; $sql = "SELECT * FROM pirerp WHERE status = '2'"; $result = mysql_query ($sql); $cargo = 0; while ($row = mysql_fetch_array($result)) { $cargo += $row['cargo']; } echo $cargo; ?> Link to comment https://forums.phpfreaks.com/topic/173477-addition-of-rows/#findComment-914491 Share on other sites More sharing options...
Philip Posted September 8, 2009 Share Posted September 8, 2009 Or if thats all you want you can use SUM in MySQL: $sql = "SELECT SUM(cargo) as sum FROM pirerp WHERE status = '2'"; Link to comment https://forums.phpfreaks.com/topic/173477-addition-of-rows/#findComment-914498 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.