kingsbest Posted May 14, 2011 Share Posted May 14, 2011 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>%</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 Quote Link to comment https://forums.phpfreaks.com/topic/236429-stats-calculation/ Share on other sites More sharing options...
Insecure Posted May 14, 2011 Share Posted May 14, 2011 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>&#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>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/236429-stats-calculation/#findComment-1215522 Share on other sites More sharing options...
kingsbest Posted May 15, 2011 Author Share Posted May 15, 2011 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 &#37; 1 John Amison 142 13 1 10 2 2 Neal Davies 108 8 0 5 3 best wishes, John. Quote Link to comment https://forums.phpfreaks.com/topic/236429-stats-calculation/#findComment-1215629 Share on other sites More sharing options...
wildteen88 Posted May 15, 2011 Share Posted May 15, 2011 $percentage should be $percent Quote Link to comment https://forums.phpfreaks.com/topic/236429-stats-calculation/#findComment-1215630 Share on other sites More sharing options...
kingsbest Posted May 15, 2011 Author Share Posted May 15, 2011 Thanks to both wildteen88 and Insecure Its simply amazing and works, the world of php is mind blowing! Thank you!!! John Quote Link to comment https://forums.phpfreaks.com/topic/236429-stats-calculation/#findComment-1215636 Share on other sites More sharing options...
Insecure Posted May 15, 2011 Share Posted May 15, 2011 No problem, sorry I forgot what I called it apparently lol. Thanks for the catch wildteen. Quote Link to comment https://forums.phpfreaks.com/topic/236429-stats-calculation/#findComment-1215809 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.