MySQL Forums
Forum List  »  Newbie

Re: Display sum of table in one line of text?
Posted by: Claude Martin
Date: March 28, 2005 03:09PM

> Total Number of Terrorist Killed = (Total of Kills
> column here)
> Total Number of Friendly Losses = (Total of Deaths
> column here)

you get that by a usual GROUP BY using SUM() on the field that holds the kills.

> Team Skill Score = (Total Kills / Total Deaths =
> Score)

this you can get using php. when you have the two values you can calculate the team skill score.

> I figured that if I can make one line work, it is
> just a case of copying the same bit of code for
> the other, modifying the differing values between
> them.

yes and sometimes you can make a function so you can use that bit of code again and again.

> I have tried many variations of code, but the most
> I managed to get displayed was 'Resource Id=6'.
> lol

yeah that happens when you output the value of the result instad of the array that you get using mysql_fetch_*. btw: i prefer mysql_fetch_assoc but *_row is ok too.

> I am a complete novice to php/mysql (started
> learning on Saturday), so please make things very
> clear. I have looked at those MySQL reference
> manuals, and tbh, they are very hard to follow for
> someone who is completely new to it. :(

just forget about that rollup stuff
what you want is a simple group by
this is like distinct (that will ignore all duplicate rows so the results are unique)
group by will make the field that you choose unique in the result. so grouping by team will group all rows that have the same team. but the result would not be of any use when you SELECT *. so you have to use SUM()
something like this:
SELECT team, SUM(kills) as kills, SUM(deaths) as deaths FROM myclanwarz GROUP BY team WHERE team = 123

here you get the sum of the kills and deaths of team (ID) 123
(note: the "AS" in the select clause is very importent when using mysql_fetch_assoc but nor for _row)
if you wont the teamname woud have to use JOIN.
this should return only one row so you dont need a while-loop in php but you sill have to use a mysql_fetch_* function.

ok its late and i dont know what im writing. ask if theres anything you want to know and i will respond tomorrow.

Gute Nacht,
Claude

http://animalliberation.tk http://veganismus.ch
http://maqi.de http://tierrechtskochbuch.de

Options: ReplyQuote


Subject
Written By
Posted
Re: Display sum of table in one line of text?
March 28, 2005 03:09PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.