Get only last value of a dynamic array
Posted: Mon Jun 28, 2004 7:07 am
Hi All,
I am trying to only show the last and final value of each array.
The problem is, each array is not a set number of values, and therefore I have no way to get the last one in each set.
Any help would be great.
Here is the code I have:
I am trying to only show the last and final value of each array.
The problem is, each array is not a set number of values, and therefore I have no way to get the last one in each set.
Any help would be great.
Here is the code I have:
Code: Select all
<?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>
<table border="1" align="center">
<?php do {
$a = $row_rsgetinfo['Grandtotal'];
$b = $row_rsgetinfo['magicnum'];
$c = $row_rsgetinfo['GolferID'];
foreach($name as $test1 => $total)
{
$e = $total;
}
switch($a - $b)
{
// Look for people who got 10 points
case "0":
case "8":
case "16":
case "24":
case "-8":
case "-16":
case "-24":
$name[$c] += "10";
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":
$name[$c] += "9";
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":
$name[$c] += "8";
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":
$name[$c] += "7";
break;
// Look for people who got 6 points
case "4":
case "12":
case "20":
case "-4":
case "-12":
case "-20":
$name[$c] += "6";
break;
default:
$name[$c] += "0";
break;
}
?>
<tr>
<td width="78"><div align="center">Tot Score</div></td>
<td width="78"><div align="center">Magic Num</div></td>
<td width="78"><div align="center">Name of Golfer</div>
</td>
<td width="73"><div align="center">Points Given</div>
</td>
</tr>
<tr>
<td><div align="center"><?php echo $row_rsgetinfo['Grandtotal']; ?></div></td>
<td><div align="center"><?php echo $row_rsgetinfo['magicnum']; ?></div>
</td>
<td><div align="center"><?php echo $row_rsgetinfo['FirstName']; ?> <?php echo $row_rsgetinfo['LastName']; ?> </div>
</td>
<td><center>
<?php echo $e; ?>
</center>
</td>
</tr>
<?php } while ($row_rsgetinfo = mysql_fetch_assoc($rsgetinfo)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($rsgetinfo);
?>