Jump to content

Basketball STats


vegasscorp

Recommended Posts

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 this
I 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:
<?php
mysql_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.
Link to comment
https://forums.phpfreaks.com/topic/33322-basketball-stats/
Share on other sites

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]
Link to comment
https://forums.phpfreaks.com/topic/33322-basketball-stats/#findComment-155700
Share on other sites

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/path/testing11.php on line 33
The 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

Link to comment
https://forums.phpfreaks.com/topic/33322-basketball-stats/#findComment-156329
Share on other sites

[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 man

Nate
Link to comment
https://forums.phpfreaks.com/topic/33322-basketball-stats/#findComment-156336
Share on other sites

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 86
0

<?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.
Link to comment
https://forums.phpfreaks.com/topic/33322-basketball-stats/#findComment-157018
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.