Jump to content

Recommended Posts

I have a table of members (18) with games played, won, drawn, lost and would like to know if its possible to have the points and percentage update automatically, example-

ID        Member             Grade Played Won Drawn Lost Points %

1 Player name             142 13         1         10         2   6     46.15

 

My web-page is currently static and i go to http://math.about.com/library/weekly/aa061502a.htm  fill in the games played and points and it gives the percentage, i have very little knowledge of php and by some miracle have managed to create a database using wamp and have extracted the data onto local host web page, my code as follows please let me know if i have any errors-


<?php
require "connect.inc.php"; 


echo "<table width='700'>
<tr>
<th></th>
<th>Member</th>
<th>Grade</th>
<th>Played</th>
<th>Won</th>
<th>Drawn</th>
<th>Lost</th>
<th>Points</th>
<th>&#37;</th>
</tr>";

$result = mysql_query("SELECT * FROM members");

while ($row = mysql_fetch_array($result)) 
  {
  echo "<tr>";
  echo "<td>" . $row['id'] . "</td>";
  echo "<td>" . $row['member'] . "</td>";
  echo "<td>" . $row['grade'] . "</td>";
  echo "<td>" . $row['played'] . "</td>";
  echo "<td>" . $row['won'] . "</td>";
  echo "<td>" . $row['drawn'] . "</td>";
  echo "<td>" . $row['lost'] . "</td>";
  echo "<td>" . $row['points'] . "</td>";
  echo "<td>" . $row['percentage'] . "</td>";
  echo "</tr>";
  }
echo "</table>";


?> 

Please tell me how i can have the points and percentage update automatically and keep in mind im a novice with php.

Best wishes,

John

Link to comment
https://forums.phpfreaks.com/topic/236429-stats-calculation/
Share on other sites

How about this:

 

<?php
require "connect.inc.php"; 


echo "<table width='700'>
<tr>
<th></th>
<th>Member</th>
<th>Grade</th>
<th>Played</th>
<th>Won</th>
<th>Drawn</th>
<th>Lost</th>
<th>Points</th>
<th>&#38;#37;</th>
</tr>";

$result = mysql_query("SELECT * FROM members");

while ($row = mysql_fetch_array($result)) 
  {
  $percent = round($row['points']/$row['played']*100, 2);
  echo "<tr>";
  echo "<td>" . $row['id'] . "</td>";
  echo "<td>" . $row['member'] . "</td>";
  echo "<td>" . $row['grade'] . "</td>";
  echo "<td>" . $row['played'] . "</td>";
  echo "<td>" . $row['won'] . "</td>";
  echo "<td>" . $row['drawn'] . "</td>";
  echo "<td>" . $row['lost'] . "</td>";
  echo "<td>" . $row['points'] . "</td>";
  echo "<td>" . $percentage. "</td>";
  echo "</tr>";
  }
echo "</table>";


?> 

Link to comment
https://forums.phpfreaks.com/topic/236429-stats-calculation/#findComment-1215522
Share on other sites

Thanks Insecure,

  I'm guessing i now leave points and percentage empty in my database, i then replaced my code with yours and got the following-

 

Notice: Undefined variable: percentage in C:\wamp\www\Website\player_stats_test.php on line 107

 

Notice: Undefined variable: percentage in C:\wamp\www\Website\player_stats_test.php on line 107

 

ID Member       Grade Played Won Drawn Lost  Points &#38;#37;

1 John Amison 142         13         1         10    2

2 Neal Davies 108        8         0         5         3

 

best wishes,

John.

 

 

Link to comment
https://forums.phpfreaks.com/topic/236429-stats-calculation/#findComment-1215629
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.