UPDATE: Ok, thanks everyone. But, when I replace var with $ i
now get these errors:
array_multisort()[function.array-multisort]: Argument #1 is expected to be an array or a sort flag
and
max()[function.max]: When only one parameter is given, it must be an array
This should be pretty easy to follow looking at my code, but can anyone tell me why I am getting this error when I run my code?
Parse error: syntax error, unexpected T_VAR
I want to sort the data by player number, and then the highest point row should be colored red:
file1.php
<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>
<title>Fantasy Football</title>
</head>
<body>
<form action="roster.php" method="POST">
<table border="1">
<tr><td>Player Name</td><td><input type="text" name="name"</td></tr>
<tr><td>Position</td><td><input type="text" name="position"</td></tr>
<tr><td>Number</td><td><input type="text" name="number"</td></tr>
<tr><td>Team</td><td><input type="text" name="team"</td></tr>
<tr><td>Points per game</td><td><input type="text" name="points"</td></tr>
<tr><td colspan="2" align="center"><input type="submit"></td></tr>
</table>
</form>
</body>
</html>
roster.php
<?php
for($i = 0; $i < sizeof($players); $i++) {
list($name[],$team[],$number[],$position[],$points[]) = explode('|', $players[$i]);
}
array_multisort($number, $position, $name, $team, $points, SORT_DESC);
var mostPoints = max($points);
for($i = 0; $i < sizeof($players); $i++) {
if($points[$i]==mostPoints){
echo '<tr style="background:#F44">';
}else{
echo '<tr>';
}
echo '<td>'.$name[$i].'</td><td>'.$team[$i].'</td><td>'.$number[$i].'</td>
<td>'.$position [$i].'</td><td>'.$points[$i].'</td></tr>';
}
?>
Have you been using JavaScript a lot lately (or old PHP 4 OO)?
PHP's only use of the
var
keyword was for old PHP4 style object property definitons.Drop the
var
part.Also, don't forget the PHP variable sigil
$
.yup, you need $mostPoints, not var mostPoints