Madatan Posted November 12, 2006 Share Posted November 12, 2006 Okey so here is what I want to do.I wanna get all the rows with ownerid = 1 and when I get them I wanna add the result in the column bonus for each row into one single variable.So if I got let's say three rows with the ownerid 1, and every row got the column bonus to 4. Then I want a variable to be 4 + 4 + 4.Anyone understanding or am I simply writing jibberish? :p[code]$query = "SELECT column FROM get_rows WHERE ownerid = '1'";$result = mysql_query($query) or die('Error : ' . mysql_error());$bonus = //I want the column results here.[/code] Link to comment https://forums.phpfreaks.com/topic/27003-reading-a-table-and-adding-up-the-results/ Share on other sites More sharing options...
trq Posted November 12, 2006 Share Posted November 12, 2006 [code]SELECT SUM(bonus) as total_bonus FROM tbl WHERE ownerid = 1;[/code] Link to comment https://forums.phpfreaks.com/topic/27003-reading-a-table-and-adding-up-the-results/#findComment-123470 Share on other sites More sharing options...
Madatan Posted November 12, 2006 Author Share Posted November 12, 2006 excellent, but how do I echo the total_bonus? I cant just do echo $total_bonus, so how do I do that= Link to comment https://forums.phpfreaks.com/topic/27003-reading-a-table-and-adding-up-the-results/#findComment-123584 Share on other sites More sharing options...
trq Posted November 12, 2006 Share Posted November 12, 2006 Same as always.[code]<?php$query = "SELECT SUM(bonus) as total_bonus FROM tbl WHERE ownerid = 1;";if ($result = mysql_query($query)) { if (mysql_num_rows($result) > 0) { $row = mysql_fetch_assoc($result); echo $row['total_bonus']; }} else { echo mysql_error();}?>[/code] Link to comment https://forums.phpfreaks.com/topic/27003-reading-a-table-and-adding-up-the-results/#findComment-123623 Share on other sites More sharing options...
Madatan Posted November 13, 2006 Author Share Posted November 13, 2006 glorious thanks! Link to comment https://forums.phpfreaks.com/topic/27003-reading-a-table-and-adding-up-the-results/#findComment-123849 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.