I want to set up a small league for my friends when we play poker.
There are only 8 of us and I have created the database with our names and each of the weeks we will play. We will play for 8 weeks and each week i will go in and input the points for each of us.
I would like the total column on the page give a running total so far up to week 8.
I have tried several different methods but each time i try i get an empty total column.
This is my code to call all the scores to the page. You can see the code i tried to make the totals
<?php
// This is to connect to and open the database
$dbhost = 'localhost';
$dbuser = 'user';
$dbpass = 'pass';
$dbname = 'name';
$table = 'table';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
//$query = "SELECT wk1, wk2, wk3, wk4, wk5, wk6, wk7, wk8, name, SUM(wk1 + wk2 + wk3 + wk4 + wk5 + wk6 + wk7 + wk8) AS total FROM league GROUP BY name";
$query = "SELECT * FROM league ORDER by total ASC";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
#Opening tag...
echo "
<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<th class=\"name\">Name</th>
<th class=\"week\">Wk 1</th>
<th class=\"week\">Wk 2</th>
<th class=\"week\">Wk 3</th>
<th class=\"week\">Wk 4</th>
<th class=\"week\">Wk 5</th>
<th class=\"week\">Wk 6</th>
<th class=\"week\">Wk 7</th>
<th class=\"week\">Wk 8</th>
<th class=\"total\">Total</th>
</tr>
";
while ($row = mysql_fetch_assoc ($result)) {
$total = $row['total'];
$name = $row['name'];
$wk1 = $row['wk1'];
$wk2 = $row['wk2'];
$wk3 = $row['wk3'];
$wk4 = $row['wk4'];
$wk5 = $row['wk5'];
$wk6 = $row['wk6'];
$wk7 = $row['wk7'];
$wk8 = $row['wk8'];
#this will print a new row for each photo..
echo "
<tr>
<td class=\"name\">$name</td>
<td class=\"week\">$wk1</td>
<td class=\"week\">$wk2</td>
<td class=\"week\">$wk3</td>
<td class=\"week\">$wk4</td>
<td class=\"week\">$wk5</td>
<td class=\"week\">$wk6</td>
<td class=\"week\">$wk7</td>
<td class=\"week\">$wk8</td>
<td class=\"total\">$total</td>
</tr>";
}
echo "</table>";
?>
Obviously I am doing something wrong otherwise it would work, but not being too advanced in php I cannot find the answer.
I would also like to add a field based on percentages but that would come later. I thought I could use the same functions as is available in MS Excel, for example I would like to have a count of how many times each one played.
But really want the total column sorted and I will work on the others over time (not really important right now)
I am grateful for you taking the time to read this and even more if you decide you can help me out.
Many Thanks