Greysoul Posted March 14, 2010 Share Posted March 14, 2010 hello all, i'm trying to tackle something thats been owning me as of late. my db is for a league in a game, where you insert stats so that people can view results of games. this is stored in the table, Scorecard. there's many games, so there are duplicate player name entries. I'm using this table to also display my results on the page. i can easily use the SUM() in my query to add up all of one players stats on his personal page. on the clan webpage, it shows every players stats listed in a table. if i add WHERE Clan='NoF', it ends up tallying up every player in that said clan and only showing one name. this is how i make it show a result of just one player, as if its on that players specific page only. how do i get this to loop for each player on the clan page to make it look like this for example: http://sparkgn.com/d.php?p=clan&&clan=12 instead of just http://sparkgn.com/d.php?p=player&&player=216 (ignore game statistics, i can do that fine already). any suggestions? $playersum=mysql_query(" SELECT *, Count(Player) AS pgp, SUM(Score) AS ps, SUM(Kills) AS pk, SUM(Deaths) AS pd, SUM(Attempts) AS pfa, SUM(Caps) AS pfc, SUM(MVP) AS pmvp FROM Scorecard WHERE Player='Greysoul'") or die(mysql_error()); while($psum=mysql_fetch_array($playersum)){ echo "<tr>"; echo "<td>".$psum['Player']."</td>"; echo "<td>".$psum['pgp']."</td>"; echo "<td>".$psum['ps']."</td>"; echo "<td>".$psum['pk']."</td>"; echo "<td>".$psum['pd']."</td>"; $pspg=$psum['ps'] / $psum['pgp']; echo "<td>".round($pspg, 2)."</td>"; $pkpg=$psum['pk'] / $psum['pgp']; echo "<td>".round($pkpg, 2)."</td>"; $pkd=$psum['pk'] / $psum['pd']; echo "<td>".round($pkd, 2)."</td>"; echo "<td>".$psum['pfa']."</td>"; echo "<td>".$psum['pfc']."</td>"; $pfp=$psum['pfc'] / $psum['pfa'] * 100; echo "<td>".round($pfp, 2). "%" ."</td>"; echo "<td>".$psum['pmvp']."</td>"; echo "</tr>"; } echo "</table>"; Link to comment https://forums.phpfreaks.com/topic/195191-hard-to-explain-what-i-need-help-with-loop/ Share on other sites More sharing options...
TeddyKiller Posted March 14, 2010 Share Posted March 14, 2010 First of all, it'd do it as.. if(mysql_num_rows($playersum) > 0){ echo '<table>'; while($psum=mysql_fetch_array($playersum)){ echo "<tr>"; echo "<td>".$psum['Player']."</td>"; echo "<td>".$psum['pgp']."</td>"; echo "<td>".$psum['ps']."</td>"; echo "<td>".$psum['pk']."</td>"; echo "<td>".$psum['pd']."</td>"; $pspg=$psum['ps'] / $psum['pgp']; echo "<td>".round($pspg, 2)."</td>"; $pkpg=$psum['pk'] / $psum['pgp']; echo "<td>".round($pkpg, 2)."</td>"; $pkd=$psum['pk'] / $psum['pd']; echo "<td>".round($pkd, 2)."</td>"; echo "<td>".$psum['pfa']."</td>"; echo "<td>".$psum['pfc']."</td>"; $pfp=$psum['pfc'] / $psum['pfa'] * 100; echo "<td>".round($pfp, 2). "%" ."</td>"; echo "<td>".$psum['pmvp']."</td>"; echo "</tr>"; } echo "</table>"; } else { echo 'No rows are being found'; } If that dont work then it's the query. It's finding no rows, which then you check if there are rows by accessing your database, if there are rows, then your query is wrote wrong. Link to comment https://forums.phpfreaks.com/topic/195191-hard-to-explain-what-i-need-help-with-loop/#findComment-1025919 Share on other sites More sharing options...
Greysoul Posted March 14, 2010 Author Share Posted March 14, 2010 yeah you'd have to change the query to preform the action i'm trying to get, what i showed you was how i got the results for one name. that's also partly what i need help with i suppose. Link to comment https://forums.phpfreaks.com/topic/195191-hard-to-explain-what-i-need-help-with-loop/#findComment-1025920 Share on other sites More sharing options...
wildteen88 Posted March 14, 2010 Share Posted March 14, 2010 If you want to display the stats for every player then you can use the following query SELECT *, Count(Player) AS pgp, SUM(Score) AS ps, SUM(Kills) AS pk, SUM(Deaths) AS pd, SUM(Attempts) AS pfa, SUM(Caps) AS pfc, SUM(MVP) AS pmvp FROM Scorecard GROUP BY Player Link to comment https://forums.phpfreaks.com/topic/195191-hard-to-explain-what-i-need-help-with-loop/#findComment-1025926 Share on other sites More sharing options...
Greysoul Posted March 14, 2010 Author Share Posted March 14, 2010 oh my, that certainly worked. i've never even heard of GROUP BY. i'm kind of a beginner, what does that do exactly? unfortunately my common sense isn't kicking in. Link to comment https://forums.phpfreaks.com/topic/195191-hard-to-explain-what-i-need-help-with-loop/#findComment-1025943 Share on other sites More sharing options...
TeddyKiller Posted March 14, 2010 Share Posted March 14, 2010 http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html Link to comment https://forums.phpfreaks.com/topic/195191-hard-to-explain-what-i-need-help-with-loop/#findComment-1026004 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.