Jump to content

PHP help!


kingsbest

Recommended Posts

Hi im new here and new to php coding, i have creating a database for testing purposes using wamp, i want to publish the contents as follows-

Player Grade Played    Won  Drawn Lost Points %

J Bloggs    150            16          10    3        3

 

I then need the php to fill in the points total and the percentage, I think the formula is as follows-

points  formula- =won+0.5*drawn

& formula- =Percentage/(won+drawn+lost)*100

 

the code i have put together is as follows-

<?php
$con = mysql_connect("localhost","root","passwordgoeshere");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("fentonch_performancetable", $con);
$result = mysql_query("SELECT * FROM playersperformance");

echo "<table width='650'>
<tr>
<td>Player</td>
<td>Grade</td>
<td>Played</td>
<td>Won</td>
<td>Drawn</td>
<td>Lost</td>
<td>Points</td>
<td>&#37;</td>
</tr>";

while($row = mysql_fetch_array($result))
  {

     $played = $row['Played'];
     if ($played>0)
       {
            $Points = ($row['Won'] + ($row['Drawn'] * 0.5));
            $Percentage = ((($row['Won'] + ($row['Drawn'] * 0.5 )) / $played) * 100);
            mysql_query("UPDATE playersperformance SET Points = " & $Points & " AND Percentage = " & $Percentage & "WHERE Players = " & $row['Players']);
        }

   echo "<tr>";
  echo "<td>" . $row['players'] . "</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>";
mysql_close($con);
?>

The table appears but with a "0" in the points total and nothing in the percentage row, i also get the following lines-

Notice: Undefined index: Played in C:\wamp\www\chess_website\includes\playerstat_data_input.inc.php on line 25

 

Notice: Undefined index: players in C:\wamp\www\chess_website\includes\playerstat_data_input.inc.php on line 34

 

Notice: Undefined index: percentage in C:\wamp\www\chess_website\includes\playerstat_data_input.inc.php on line 41

 

Notice: Undefined index: Played in C:\wamp\www\chess_website\includes\playerstat_data_input.inc.php on line 25

 

Notice: Undefined index: players in C:\wamp\www\chess_website\includes\playerstat_data_input.inc.php on line 34

 

Notice: Undefined index: percentage in C:\wamp\www\chess_website\includes\playerstat_data_input.inc.php on line 41

 

Apologies if this is posted in the wrong place.

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/174433-php-help/
Share on other sites

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.