A
Anonymous
Guest
I have a table that includes many entrants that have EACH competed in 10 events. Each event has a specific point total. What i'm trying to do is calculate the highest 7 values for EACH participant and enter that total into a variable called $overall_seven.
there are TEN point values (i.e. one_points, two_points,etc..) and i need to sort them and total the hightest 7 values into the variable $overall_seven.
any ideas?
-Michael
Code:
$result = mysql_query('SELECT * from table);
while ($row = mysql_fetch_assoc($result))
{
foreach ($row as $key => $value)
{
if (strstr($key, '_points')) {$points[] = $value;}
}
$overall = 0;
for ($i = 0; $i < 7; $i++)
{
$overall+= $points[$i];
}
echo $row['first_name'] . ' ' . $row['last_name'] . '<br>
the total for the highest 7 values = ' . $total . '<br><br>';
$sql = "UPDATE table SET overall_seven='$overall' WHERE table_id='$row[table_id]'";
$result = mysql_query($sql) or die('error: '. mysql_error());
}
there are TEN point values (i.e. one_points, two_points,etc..) and i need to sort them and total the hightest 7 values into the variable $overall_seven.
any ideas?
-Michael