I am attempting to write a code that will update two columns of my table for every entry in the table. The odd thing about it is I have to use other points of data from every entry to find out how to update each entry. I have tried to accomplish this by embedding one While loop inside another. As a whole it accomplishes the task, but only for the first entry in my table. Here is the code:
$result = mysql_query("SELECT * FROM subjects ");
While ($row = mysql_fetch_array($result)) {
$subject = $row['name'];
$a = $row['a'];
$b = $row['b'];
$c = $row['c'];
$d = $row['d'];
$e = $row['e'];
$f = $row['f'];
$g = $row['g'];
$h = $row['h'];
$i = $row['i'];
While ($row = mysql_fetch_array($result)) {
$bestpercent == 0;
$distance = sqrt(pow($a - $row['a'], 2) + pow($b - $row['b'], 2) + pow($c - $row['c'], 2) + pow($d - $row['d'], 2) + pow($e - $row['e'], 2) + pow($f - $row['f'], 2) + pow($g - $row['g'], 2) + pow($h - $row['h'], 2) + pow($i - $row['i'], 2));
$compatibility = round(100 * (1 - pow($distance / $maxdistance, 2)), 0);
If ( $bestpercent < $compatibility ) {
$bestpercent = $compatibility;
$bestmatch = $row['name'];
}
}
mysql_query("UPDATE subjects SET bestname='$bestmatch' WHERE name='$subject' ") or die(mysql_error());
mysql_query("UPDATE subjects SET bestpercent='$bestpercent' WHERE name='$subject' ") or die(mysql_error());
}
Like I said, it comes up with the correct results, but only for the first entry in my table. Any help would by greatly appreciated, thanks!