Can somebody help me finish a long-going coding problem i'm encountering. This coding works perfectly on the first db entry only, and then gives me the folowing error:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource
$result = mysql_query('SELECT table_id,first_name,last_name,one_points,two_points,three_points,four_points,five_points,six_points,seven_points,eight_points,nine_points,ten_points from table');
while ($row = mysql_fetch_assoc($result))
{
foreach ($row as $key => $value){
if (strstr($key, '_points')) {
$points[] = $value;
}
}
rsort($points);
$total = 0;
for ($i = 0; $i < 7; $i++)
{
$total += $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='$total' WHERE table_id='$row[table_id]'";
$result = mysql_query($sql) or die('error: '. mysql_error());
}
is this looping properly?
-mike
ps. my goal here is to loop through an existing db structure and total the highest 7 values of 10 possible point values, and then enter that new value as $overall_seven into my db.