hello,
QUOTE
I am not sure about what should be primary key for the STATS table
I think you have to add a new auto increment field and make it as primary key, this is usable for deleting and updating.
how would I take the data to make averages?
you have to execute mysql query to retreive the avarage then use php to read it and convert it to viewable html;
something like:
sql
select game_id,count(game_id) as games_count,count(player_id) as players_count from STATS group by game_id
think of the above code as this:
first you group all rows with similar game_id together, and this will also group all player in the same game too
count is an agregate function
by applying it on(game_id) will return the game's count and becaue of the grouping is by game_id too, the count(player_id) will return the count of players(that have been recorded) on that specific game
of course you can add more counts as needed but I realy know nothing about sports..
and for example,if you want to get the count of each player's points:
sql
select player_id,count(points) as pointscount from STATS group by player_id
here is an php example from php manual chm file( you can find it here
http://www.php.net/docs.php ) with some modifications
php
<?php
$conn = mysql_connect("localhost", "mysql_user", "mysql_password");
if (!$conn) {
echo "Unable to connect to DB: " . mysql_error();
exit;
}
if (!mysql_select_db("mydbname")) {
echo "Unable to select mydbname: " . mysql_error();
exit;
}
//here you type the sql string you want to execute
$sql = "select game_id,count(game_id) as games_count,count(player_id) as players_count from STATS group by game_id";
$result = mysql_query($sql);
if (!$result) {
echo "Could not successfully run query ($sql) from DB: " . mysql_error();
exit;
}
if (mysql_num_rows($result) == 0) {
echo "No rows found, nothing to print so am exiting";
exit;
}
// While a row of data exists, put that row in $row as an associative array
// Note: If you're expecting just one row, no need to use a loop
// Note: If you put extract($row); inside the following loop, you'll
// then create $games_count, $players_count, and $game_id
$html="<table>";
while ($row = mysql_fetch_assoc($result)) {
// here is the part where you extra the data from rows to generate html table
$html .="<tr>";
$html .="<td>".$row["game_id"]."</td>";
$html .="<td>".$row["games_count"]."</td>";
$html .="<td>".$row["players_count"]."</td>";
$html .="</tr>";
}
$html .="</table>"
echo $html;
mysql_free_result($result);
?>
about calculating averages, i don't realy know how you want to do that, because i can think of multiple ways (average points per game, average points per player, average points per player per gane or over all averages...)
so, it's just a matter of what you need
note: php and mysql are available for free and there are a lot of free resources over the net
hope it helps