Forum Moderators: coopster
I would like to display stats and totals. I have created the data base with three tables Players,games,stats. the bulk of the stats are entered in the stats table.
The stats table is like this.
id ¦ pid ¦ gid ¦ pts ¦ thr ¦ rbs ¦ blks ¦ ast ¦ etc.
1----10-----1----19-----2-----2-----3-----3----etc.
2-----5-----1----9------0-----1-----1-----1----etc.
3-----7-----1----5------1-----0-----2-----6----etc.
4----10-----2----12-----1-----2-----4-----2----etc.
The Id is unique but the pid and gid are unique for players and games.
All I need to do is display the sum of all unique gid on each line on one stats page. Then for each players page display the sum for unique gid on each line for that certain pid (player).
I need help on the php code to use to display results.
Please help. much gratitude
$query = "SELECT pid,COUNT(gid) FROM table_name GROUP BY pid LIMIT $start, $length";
$query = "SELECT gid FROM table_name GROUP BY gid LIMIT $start, $length";
//query database
$number = mysql_num_rows($result);
I hope this has helped a little bit :)
Good luck!
<?php
$link = mysql_connect("localhost","username","password");
mysql_select_db("db_name");
$query = "SELECT gid FROM table_name GROUP BY gid"; //try this at first without the limit
$result = mysql_query($query,$link);
$number = mysql_num_rows($result);
echo 'Number of games played: '.$number;
$query = "SELECT pid,COUNT(gid) AS CTgid FROM table_name GROUP BY pid LIMIT $start, $length"
$result = mysql_query($query,$link);
while($row = mysql_fetch_array($result)) {
echo 'Player ID: '.$row['pid'].'<br/>';
echo 'Number of games: '.$row['CTgid'].'<br/><br/>';
}
mysql_close($link);
?>
I hope this is a little more clear :)
<?php require_once('../Connections/Connection.php');?>
<?php
mysql_select_db($database_Connection, $Connection);
$query_statz = "SELECT * FROM stats ORDER BY ID ASC";
$statz = mysql_query($query_statz, $Connection) or die(mysql_error());
$row_statz = mysql_fetch_assoc($statz);
$totalRows_statz = mysql_num_rows($statz);
mysql_select_db($database_Connection, $Connection);
$query_playerz = "SELECT * FROM players";
$playerz = mysql_query($query_playerz, $Connection) or die(mysql_error());
$row_playerz = mysql_fetch_assoc($playerz);
$totalRows_playerz = mysql_num_rows($playerz);
mysql_select_db($database_Connection, $Connection);
$query_gamez = "SELECT * FROM games";
$gamez = mysql_query($query_gamez, $Connection) or die(mysql_error());
$row_gamez = mysql_fetch_assoc($gamez);
$totalRows_gamez = mysql_num_rows($gamez);
mysql_select_db($database_Connection, $Connection);
$query_gidstatz = "SELECT ID, gid, `Date`, Player, `Result`, Opponent, Location, Oppscore, Ourscore, Pts, `2FG`, `3FG`, FTM, FTA, Offreb, Defreb, Totreb, `TO`, Stl, Asst, Blk, PF FROM stats ORDER BY gid ASC";
$gidstatz = mysql_query($query_gidstatz, $Connection) or die(mysql_error());
$row_gidstatz = mysql_fetch_assoc($gidstatz);
$totalRows_gidstatz = mysql_num_rows($gidstatz);
?>
The code you just gave me is that in the <body> </body> or at top of page?
If what you gave me is what goes on top which I assume.
What code do I put in <td> </td> body to actually display the results?
<snip>
the link above shows what looked like last season. The difference last season was I made a table for each player and all I did in Dreamweaver mx 2004 was just use the echo command to display in result in body. It was suggested that I not make so many tables and just make three tables. Games,Players, and Stats. All the stats go into stats table.
I want to thankyou for your help. I don't do this as carreer I just volunteered to do site for the varsity high school basketball team. Happy New Year
[edited by: encyclo at 3:59 am (utc) on Jan. 1, 2007]
[edit reason] no URLs please, see TOS [webmasterworld.com] [/edit]
<?php
mysql_select_db($database_Connection, $Connection);
$query = "SELECT gid FROM stats GROUP BY gid"; //try this at first without the limit
$result = mysql_query($query,$link); //this is line 35
$number = mysql_num_rows($result);
echo 'Number of games played: '.$number;
$query = "SELECT pid,COUNT(gid) AS CTgid FROM stats GROUP BY pid LIMIT $start, $length"
$result = mysql_query($query,$link);
while($row = mysql_fetch_array($result)) {
echo 'Player ID: '.$row['pid'].'<br/>';
echo 'Number of games: '.$row['CTgid'].'<br/><br/>';
?>
$result = mysql_query($query);
Also, unless you have that variables $start and $length defined, you will need to either replace those with actual numbers or take the LIMIT out completely. I'd suggest the latter just to see how everything works first.
<body>
<?php
mysql_select_db($database_Connection, $Connection);
$query = "SELECT gid FROM stats GROUP BY gid"; //try this at first without the limit
$result = mysql_query($query); $number = mysql_num_rows($result);
echo 'Number of games played: '.$number;
$query = "SELECT pid,COUNT(gid) AS CTgid FROM stats GROUP BY pid LIMIT $start, $length"
$result = mysql_query($query); //this is line 68
while($row = mysql_fetch_array($result)) {
echo 'Player ID: '.$row['pid'].'<br/>';
echo 'Number of games: '.$row['CTgid'].'<br/><br/>';
?>
</body>
Is this the code I put in body if not what do I put in body? thankyou
$query = "SELECT pid,COUNT(gid) AS CTgid FROM stats GROUP BY pid LIMIT $start, $length"
Two of them are because you do not ave $start and $length defined (or do you?). So I'd take those out until you need to limit the results. And the third error is that the line does not end with a semicolon. So it would then look like this:
$query = "SELECT pid,COUNT(gid) AS CTgid FROM stats GROUP BY pid";
>>>Is this the code I put in body if not what do I put in body?
Yes this is the code you would put in the body because this is going to echo you player stats. Of course if you have more player stats you are going to have to select them and echo them here, too, but we need to have something working first ;)
<?php
mysql_select_db($database_Connection, $Connection);
$sql = "SELECT pid, SUM(pts) AS Sum_pts FROM `stats` GROUP BY gid";
$result = mysql_query($sql) or die(mysql_error());
$i = mysql_fetch_array($result);
?>
<?php echo $i['Sum_pts'];?>
Also this is only show pts I need it to show all stats.
I need select * sum * from stats group by gid
something like that.
Thankyou for any help.
you also need to loop this
$i = mysql_fetch_array($result);
something more like
while ($row = mysql_fetch_array($result)) {
echo '<p>',$row ['Sum_pts'];
}
that will echo all the results from your query. You can then add more to your query and then add more output inside that loop.
<?php
$query2 = "SELECT SUM(distinct Ourscore) from `stats` GROUP BY gid";
$result18 = mysql_query($query2);
$row2 = mysql_fetch_array($result18);
echo "".(round($row2[0]))." ";
?>
I want to sum all records by unique gid and show the total. Thankyou.
$result18 = mysql_query($query2) [b]or die(mysql_error());[/b]
This will give you the error from mysql so that you can correct it :)