Jump to content

[SOLVED] Sum of all rows


TimUSA

Recommended Posts

Hi again....i have googled this to death before coming here groveling for help again!

i have this query:

$query = "SELECT `skipperName` , `matchPoints` FROM `pts_table` GROUP BY `skipperName`;";
$result = mysql_query($query);
if(mysql_num_rows($result)) 
			{
				while($row = mysql_fetch_row($result))
				{
				echo'
				<table>
				<tr>
				<left><td>' . $row[0] . '</td></left><br>
				<right><td><left>' . $row[1] . '</td></right><br>
				</tr>
				</table>';
				}
			}

 

What I would actually like to do is to GROUP BY `skipperName` and add the total value of all the `match` points for that column?? am i making sense?

Link to comment
https://forums.phpfreaks.com/topic/84900-solved-sum-of-all-rows/
Share on other sites

$query = "SELECT skipperName, sum(matchPoints) as SummatchPoints FROM pts_table GROUP BY skipperName;";
$result = mysql_query($query);
if(mysql_num_rows($result)) 
			{
				while($row = mysql_fetch_row($result))
				{
				echo'
				<table>
				<tr>
				<left><td>' . $row[skipperName] . '</td></left><br>
				<right><td><left>' . $row[summatchPoints] . '</td></right><br>
				</tr>
				</table>';
				}
			}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.