MySQL Forums
Forum List  »  Newbie

Re: Display sum of table in one line of text?
Posted by: Claude Martin
Date: March 29, 2005 03:05AM

> $result = mysql_query("SELECT * FROM tfcoop ORDER
> BY score DESC",$db);

there already is a score in the database?
i have once played counter strike but im not familiar with how a member gets his score.
btw: never use SELECT *
its ok for learning mysql but its always better to tell mysql what you want.
forget everything i wrote about "team". i thought it would be the scores of the teams but you want the score of every member. i didnt read your post so i didnt know.
but it doesnt matter anyway.

>
> exec(
> "cp $picture
> http://www.tangoforce.com/images/flags/$nat";);

what is this anyway?


> echo "<table border=1>\n";

thats good for creating a dynamic table. i'd rather clode the php section by ?> so you can just write the html code and have nop problems with quotes.
->
<?
//here is some php
//you can even use this in a loop:
$foo = 0; $max = 20;
while($foo<$max) {
?>
<table> <tr><td>$foo = <?=$foo?>
</tr></tr></table>
<?
$foo++;
//and again some php

}
?>

> It is for my 'clan' website, and absically, I want
> it to display the total of the 'kills' column,
> then (on a new line) the total of the 'deaths'
> column, then I want it to display the result of
> the 'kill total' divided by the 'death total'.

all the other code looks good to but the query should be grouped as i mentioned in the other post:

something like this:
$result = mysql_query("SELECT `membername`, SUM(`kills`) as kills, SUM(`deaths`) as deaths, score FROM tfcoop GROUPY BY `membername` ORDER BY score DESC");

then you use mysql_fetch_assoc to get the keys in the array.

while($row = mysql_fetch_assoc($result)) {
echo "<b>$row[membername]</b><br>";
echo "score: $row[score]<br>";
echo "kills: $row[kills]<br>";
echo "deaths: $row[deaths]<br>";
echo "ratio: ".($row[kills]/$row[deaths])."<br>";
}

is that what you want?

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 29, 2005 03:05AM


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.