bwyant32 Posted March 21, 2012 Share Posted March 21, 2012 Ok, I am running a baseball site and we have our player stats all in a table within a database. What I have is something like this, http://www.stlbleague.com/tm.php?tid=7... Now what I would like to do is have a row at the end of the pitching and hitting stats that says "Team Totals", here is a sample code that I have pulling the pitching stats: $id = $_GET['tid']; // get var from URL /* Get data. */ $sql = "SELECT player, pos, era, w, l, sv, hold, ip, bb, k, cg, sho, whip, k9 FROM 2012pitching LEFT JOIN roster ON 2012pitching.id=roster.id WHERE tid='$id'"; $result = mysql_query($sql); ?> <table width="962" border="0" cellpadding="2" cellspacing="1" class="stats2"> <tr class='theader'> <td align='center'>PLAYER</td> <td align='center'>POS</td> <td align='center'>ERA</td> <td align='center'>W</td> <td align='center'>L</td> <td align='center'>SV</td> <td align='center'>HOLD</td> <td align='center'>IP</td> <td align='center'>BB</td> <td align='center'>K</td> <td align='center'>CG</td> <td align='center'>SHO</td> <td align='center'>WHIP</td> <td align='center'>K/9</td> </tr> <?php $alternate = "2"; while ($row = mysql_fetch_array($result)) { $field1 = $row["player"]; $field2 = $row["pos"]; $field3 = $row["era"]; $field4 = $row["w"]; $field5 = $row["l"]; $field6 = $row["sv"]; $field7 = $row["hold"]; $field8 = $row["ip"]; $field9 = $row["bb"]; $field10 = $row["k"]; $field11 = $row["cg"]; $field12 = $row["sho"]; $field13 = $row["whip"]; $field14 = $row["k9"]; if ($alternate == "1") { $color = "#ffffff"; $alternate = "2"; } else { $color = "#E4E4E4"; $alternate = "1"; } echo "<tr bgcolor=$color><td>$field1</td><td align='center'>$field2</td><td align='center'>$field3</td><td align='center'>$field4</td><td align='center'>$field5</td><td align='center'>$field6</td><td align='center'>$field7</td><td align='center'>$field8</td><td align='center'>$field9</td><td align='center'>$field10</td><td align='center'>$field11</td><td align='center'>$field12</td><td align='center'>$field13</td><td align='center'>$field14</td></tr>"; } echo "</table>"; ?> So how could I use the Team ID associated with every player that it is pulling from to add a totals row? Thanks again in advance, Bobby Quote Link to comment https://forums.phpfreaks.com/topic/259423-table-totals/ Share on other sites More sharing options...
AyKay47 Posted March 21, 2012 Share Posted March 21, 2012 intval or cast the $_GET variable to prevent SQL injection. Use Count() in the query to find totals. Quote Link to comment https://forums.phpfreaks.com/topic/259423-table-totals/#findComment-1329866 Share on other sites More sharing options...
bwyant32 Posted March 21, 2012 Author Share Posted March 21, 2012 intval or cast the $_GET variable to prevent SQL injection. Use Count() in the query to find totals. I'm lost on that one, could you show me in the code that I have? Quote Link to comment https://forums.phpfreaks.com/topic/259423-table-totals/#findComment-1329869 Share on other sites More sharing options...
AyKay47 Posted March 21, 2012 Share Posted March 21, 2012 what do you want to find the total of? Quote Link to comment https://forums.phpfreaks.com/topic/259423-table-totals/#findComment-1329877 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.