PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?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);
?>
If you don't care about keeping the array intact then [php_man]array_pop[/php_man]() will work for you.
Otherwise, use [php_man]array_reverse[/php_man](), and use the first result
<?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>
<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 array_pop(array_values($name));?>
</center>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<?php } while ($row_rsgetinfo = mysql_fetch_assoc($rsgetinfo)); ?>
</table>
</body>
</html>
<?php
mysql_free_result($rsgetinfo);
?>
it's not working because you're populating the array (see: your while-statement) while trying to determine the last element of you array (array_pop).
That's comparable to seeing the first carriage of a train coming out of a tunnel and asking "How long is the train? And what colour does the last carriage have". Answer: you don't and you can't know. Let it come out of the tunnel first. Then count.
Break down what you're trying to do into logical unit and treat every unit as seperate entity:
1. Obtain data from the database
2. Filter/Manipulate the data (e.g. determine last element of an array)
3. Display the data (in your HTML-selects).
First: PHP only: retrieve all the data from the database.
Second: PHP only: prepare the data for presentation (in your case: fetch the respective last elements of the arrays you've retrieve in the first step).
Third: HTML (interspersed with echoing of PHP-variables): create the HTML-page, including form-fields, combo-boxes etc.
Break up the webpage you've created. Put all the PHP that contains logic at the top of your page (for an explanation see: http://wiki.devnetwork.net/index.php/TemplatesTutorial and scroll down to "What is content what is logic?"). Once you've done that, close your php-tags and write your HTML.
Once you've done that and got it working, you may want to look into functions.