vegasscorp Posted January 8, 2007 Share Posted January 8, 2007 Ok I have this working But it is not repeating for each game. This is only displaying the first game. I need it to repeat and show sum of all totals for each game. stats table looks something like thisI need it to show total of all unique gid repeated on one line for each game.id | pid | gid | pts | thr | orb | drb | 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.<?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. Or something like this:<?phpmysql_select_db($database_Connection, $Connection);$query_statz = "SELECT * SUM(gid) FROM stats Group By gid";$statz = mysql_query($query_statz, $Connection) or die(mysql_error());$row_statz = mysql_fetch_assoc($statz);$totalRows_statz = mysql_num_rows($statz);?>This to display results like this<?php echo $row_statz['Pts']; ?><?php echo $row_statz['FG']; ?>ETC....Thankyou for your help. Quote Link to comment Share on other sites More sharing options...
trq Posted January 8, 2007 Share Posted January 8, 2007 You need to use a loop to go through all the results. You also need to get into the habbit of checking your results before trying to use them.[code]<?php // connect to db. $sql = "SELECT *, SUM(gid) FROM stats Group By gid"; if ($statz = mysql_query($sql)) { if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_assoc($result)) { echo $row['stats']; echo $row['Pts']; echo $row['FG']."<br />"; } } }?>[/code] Quote Link to comment Share on other sites More sharing options...
vegasscorp Posted January 9, 2007 Author Share Posted January 9, 2007 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/path/testing11.php on line 33The warning I get is above. But I'm not sure will this sum the results based on gid for each game on each line?<?php mysql_select_db($database_Connection, $Connection); $sql = "SELECT *, SUM(gid) FROM stats Group By gid"; if ($statz = mysql_query($sql)) { if (mysql_num_rows($result) > 0) { //this is line 33 while ($row = mysql_fetch_assoc($result)) { echo $row['Pts']; echo $row['2FG']; echo $row['3FG']."<br />"; } } }?>Thankyou. much Quote Link to comment Share on other sites More sharing options...
chronister Posted January 9, 2007 Share Posted January 9, 2007 [code]<?php mysql_select_db($database_Connection, $Connection); $sql = "SELECT *, SUM(gid) FROM stats Group By gid"; if ($statz = mysql_query($sql)) { if (mysql_num_rows($statz) > 0) { //this should have been $statz while ($row = mysql_fetch_assoc($result)) { echo $row['Pts']; echo $row['2FG']; echo $row['3FG'].""; } } }?>[/code]WOW, I cannot believe I corrected the almighty Thorpe... The man is a genius...but even a genius makes the occasional mistake Thorpe,Not trying to be mean or anything here, I am still learning this crap and am suprised I caught something in your post... Thanks for all your help and wisdom on here manNate Quote Link to comment Share on other sites More sharing options...
marcus Posted January 9, 2007 Share Posted January 9, 2007 Change mysql_num_rows($result) to mysql_num_rows($statz) Quote Link to comment Share on other sites More sharing options...
vegasscorp Posted January 10, 2007 Author Share Posted January 10, 2007 I tried this and get this error.Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/path/testing13.php on line 860 <?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. Quote Link to comment Share on other sites More sharing options...
marcus Posted January 10, 2007 Share Posted January 10, 2007 $result18 = mysql_query($query2) or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.