Adding Certain Values

A

Anonymous

Guest
Hello.
I'm new to php and I could use some help, if someone has the time and patience to give me a light.

My problem is: I have a MySQL table with some values (like "user", "score" and "clan") and i wanted to add the Score of all the Users of the same Clan, so i could make a clan list based on each clan score.

Can i do this?

Thank you in advance.
 
I don't quite understand your question. Do you want to create another table in the database or retrieve the results and display it on webpage?
 
Just do a query to select all of the rows in the table

then do something like this

Code:
<?php
while ($row = mysql_fetch_array($result))
{
  if ($total[$row['clan']] == FALSE)
  {
    $total[$row['clan'] = $row['score'];
  } else {
    $total[$row['clan'] += $row['score'];
  }
}
foreach($total as $key => $score)
{
  echo $key . " : " . $score;
}
?>

hope that guides you in the right direction
 
Sorry harrisonad, I didn't explain myself properly, but I wasn't even sure of what I wanted to do.

Virtuoso, that code worked out just fine! Thanks a bunch :D

Thank you for your replies.
 
Back
Top