SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Comparing Statistics

    Below is a portion of the code I use to grab stats from my hockey team database. Using this, I can display the entire roster's career stats for Goals, Assists, Points and Games Played.

    Now I'm trying to figure out how to compare all the stats, and pull out say "the leading goal scorer" and display his name and total career goals. But I'm not sure to how to do this? Any thoughts?

    Thanks,
    Greg

    $totalslist = mysql_query('SELECT name, SUM(goals) AS totalgoals, SUM(assists) AS totalassists, SUM(gamesplayed) AS totalgamesplayed, SUM(goals)+SUM(assists) AS totalpoints
    FROM players, statistics, season WHERE playerid=players.id AND seasonid=season.id GROUP BY players.id ORDER BY ' . $order . $direction);


    while ($players = mysql_fetch_array($totalslist)) {
    $name = $players['name'];
    $totalgoals = $players['totalgoals'];
    $totalassists = $players['totalassists'];
    $totalgamesplayed = $players['totalgamesplayed'];
    $totalpoints = $totalgoals + $totalassists;

  2. #2
    Twitter - @CarlBeckel busy's Avatar
    Join Date
    May 2004
    Location
    Richmond, VA, USA
    Posts
    819
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not 100% on this, but I think it would be something like this...
    Code:
    SELECT 
      name,
      SUM(goals) AS totalgoals, 
      SUM(assists) AS totalassists, 
      SUM(gamesplayed) AS totalgamesplayed
      (SUM(goals)+SUM(assists)) AS totalpoints  <-- unsure about this
    
    FROM 
      players, 
      statistics, 
      season 
    
    WHERE 
      playerid=players.id AND seasonid=season.id 
    
    GROUP BY 
      players.id 
    
    ORDER BY 
      totalpoints DESC LIMIT 1
    And the rest would be how you have it.
    Hope that helps (and hope my syntax is ok

  3. #3
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now, I wouldn't have thought it was that simple. I guess that's why I'm not a fulltime programmer. :-)

    Thanks!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •