Hi,
I have this script to automate standings of a backgammon league. It pulls info from the played matches table and displays points totals and player names.
Unfortunately, it is not working. I'm very new to this stuff and I cannot figure out what is wrong with it. Please help if you can.
Thank You
Rhyan
// create connection
// test connection
// select database
// test selection
$query = "SELECT Winner,SUM(Wins) as sWins FROM submitwk1 GROUP BY Winner ORDER BY sWins DESC";
$mysql_result = mysql_query($query,$connection);
print ("<B>") ;
print ("<Center>");
print ("<TABLE BORDER=\"4\">\n");
print ("<TR>\n");
print ("<TD BGCOLOR=\"#cccccc\"><B><font size='8'>Member Name</font><B></TD>\n");
print ("<TD BGCOLOR=\"#cccccc\"><B><font size='8'>Points</font><B></TD>\n");
print ("<TR>\n");
$mytable = md5(uniqid(rand())); #create a unique name
$sql = "CREATE TABLE $mytable (name varchar(100),Wins int(10));";
$result = mysql_query($sql,$connection);
while ($row = mysql_fetch_array($mysql_result))
{
$name = $row[0];
$Wins = $row[1];
$query2 = "SELECT SUM(Losses) FROM submitwk1 WHERE Loser = '$name'"; # now create a sql query to get a summary of wins from all lost games
$mysql_result2 = mysql_query($query2,$connection);
$row1 = mysql_fetch_row($mysql_result2);
$SumWins = $Wins+$row1[0]; #here we have the summary of all wins per Player!
$sql = "INSERT INTO $mytable (name,Wins) VALUE ('$name','$Wins');";
$result = mysql_query($sql,$connection);
}
$sql = "SELECT * FROM $mytable ORDER BY Wins;";
$result = mysql_query($sql,$connection);
while ($row = mysql_fetch_array($result))
{
$name = $row[0];
$Wins = $row[1];
print ("<TR>\n");
print ("<TD><font size='5'>$name</font></TD>\n");
print ("<TD><font size='5'>$SumWins</font></TD>\n");
print ("<TR>\n");
}
$sql = "DROP TABLE $mytable;";
$result = mysql_query($sql,$connection);
// free resources and close connection
mysql_free_result($sql_result);
mysql_close($connection);