I have some Php code that grabs information from a MySQL database.
Once I have the information I take 2 fields and minus them. Depending on the answer, I use a Switch() function to assign a new value ...ie 8.
What I need help with now is, grouping all these new values under a key.
For example, user scobu may have 8, 4, 3 ,2 in the array. I need to sum those values up.
Here is the code I have so far... Any help would be appreciated.
--------------------------------------------------
--------------------------------------------------
Code: Select all
<?php require_once('Connections/waxyourboard.php'); ?>
<?php
mysql_select_db($database_waxyourboard, $waxyourboard);
$query_rsgetinfo = "SELECT FirstName, LastName, GolferID, Enter_Score.GolfDate, (Hole1 + Hole2 + Hole3 + Hole4 + Hole5 + Hole6 + Hole7 + Hole8 + Hole9) as Grandtotal, magicnum FROM Enter_Score, Golfer, MagicNumber WHERE Golfer.GolferID = Enter_Score.Golfer AND MagicNumber.golfdate = Enter_Score.GolfDate";
$rsgetinfo = mysql_query($query_rsgetinfo, $waxyourboard) or die(mysql_error());
$row_rsgetinfo = mysql_fetch_assoc($rsgetinfo);
$totalRows_rsgetinfo = mysql_num_rows($rsgetinfo);
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<p> </p>
<p> </p>
<p><font color="#FF0000" size="4" face="Arial, Helvetica, sans-serif"><?php echo $row_rsgetinfo['FirstName']; ?> <?php echo $row_rsgetinfo['LastName']; ?></font></p>
<p> </p>
<table border="1" align="center">
<?php do {
$a = $row_rsgetinfo['Grandtotal'];
$b = $row_rsgetinfo['magicnum'];
$c = $row_rsgetinfo['GolferID'];
switch($a - $b)
{
// Look for people who got 10 points
case "0":
case "8":
case "16":
case "24":
case "-8":
case "-16":
case "-24":
$test = "10";
$name[] = $c;
break;
// Look for people who got 9 points
case "1":
case "7":
case "9":
case "15":
case "17":
case "23":
case "25":
case "-1":
case "-7":
case "-9":
case "-15":
case "-17":
case "-23":
case "-25":
$test = "9";
$name[] = $c;
break;
// Look for people who got 8 points
case "2":
case "6":
case "10":
case "14":
case "18":
case "22":
case "-2":
case "-6":
case "-10":
case "-14":
case "-18":
case "-22":
$test = "8";
$name[] = $c;
break;
// Look for people who got 7 points
case "3":
case "5":
case "11":
case "13":
case "19":
case "21":
case "-3":
case "-5":
case "-11":
case "-13":
case "-19":
case "-21":
$test = "7";
$name[] = $c;
break;
// Look for people who got 6 points
case "4":
case "12":
case "20":
case "-4":
case "-12":
case "-20":
$test = "6";
$name[] = $c;
break;
default:
$test = "0";
$name[] = $c;
break;
}
?>
<tr>
<td><div align="center">Date of Golf</div>
</td>
<td> <div align="center">Total Score</div>
</td>
<td><div align="center">Magic Number Rolled</div>
</td>
<td><div align="center">Points Given</div>
</td>
</tr>
<tr>
<td><div align="center"><?php echo $row_rsgetinfo['GolfDate']; ?></div>
</td>
<td><div align="center"><?php echo $row_rsgetinfo['Grandtotal']; ?></div>
</td>
<td><div align="center"><?php echo $row_rsgetinfo['magicnum']; ?></div>
</td>
<td><?php print_r($test); ?>
<div align="center"></div></td>
</tr>
<?php } while ($row_rsgetinfo = mysql_fetch_assoc($rsgetinfo));?>
</table>
</body>
</html>
<?php
mysql_free_result($rsgetinfo);
?>