Jump to content

Hard to explain what i need, help with loop?


Greysoul

Recommended Posts

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>";

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.

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

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.