I am trying to calculate how many wins/ loses and how many games played.
I have a database named weeks and in there i store quite a few columns but now needing to calculate the total number of wins and loses for all weeks i have searched around and found this page which shows a nice example on how to use SUM.
My table is named weeks and it looks like this
id | fs1 | fs2 | fs3 | => fs12
I have been inserting rows for each week so for example
id | fs1 | fs2 | fs3 | => fs12
1 0 1 0 1 =2 wins
2 0 1 1 1 =3 wins
So using the code from the website i linked to above; this is my code i have at present but its not working.
<?
//set connection variables
$host = "localhost";
$username = "root";
$password = "";
$db_name = "pool"; //database name
//connect to mysql server
$mysqli = new mysqli($host, $username, $password, $db_name);
//check if any connection error was encountered
if(mysqli_connect_errno()) {
echo "Error: Could not connect to database.";
exit;
}
$getTotalPoints = mysql_query("SELECT SUM(fs1 + fs2 + fs3 + fs4 + fs5 + fs6 + fs7 + fs8 + fs9 + fs10 + fs11 + fs12) wins FROM weeks");
$TotalPoints = mysql_fetch_array($getTotalPoints);
echo $TotalPoints['wins'];
?>
This code gives me the following error Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in line 6
Which is $TotalPoints = mysql_fetch_array($getTotalPoints);
When i do the query direct to the database i get the following messages
This table does not contain a unique column. Grid edit, checkbox, Edit, Copy and Delete features are not available.
Showing rows 0 - 0 ( 1 total, Query took 0.0012 sec)
wins
59