Making a table...

I’m attempting to make a table of the compatibilities of people. All these people are in the the table “subjects” in my MYSQL databse and values a-i assigned. Unfortunately, my attempts have failed repeatedly, but I don’t know why. Here is the code I thought would work:

[code]$result = mysql_query(SELECT * FROM subjects WHERE sex = ‘1’ ");
$row = mysql_fetch_array($result);
$result1 = mysql_query(SELECT * FROM subjects WHERE sex = ‘0’ ");
$row1 = mysql_fetch_array($result1);

echo “

”;
while ($row = mysql_fetch_array($result)) {
echo “”;
echo “";
while ($row1 = mysql_fetch_array($result1)) {
$distance = sqrt(pow($row[‘a’] - $row1[‘a’], 2) + pow($row[‘b’] - $row1[‘b’], 2) + pow($row[‘c’] - $row1[‘c’], 2) + pow($row[‘d’] - $row1[‘d’], 2) + pow($row[‘e’] - $row1[‘e’], 2) + pow($row[‘f’] - $row1[‘f’], 2) + pow($row[‘g’] - $row1[‘g’], 2) + pow($row[‘h’] - $row1[‘h’], 2) + pow($row[‘i’] - $row1[‘i’], 2));
$compatibility = round(100 * (1 - pow($distance / $maxdistance, 2)), 0);
echo “";
}
echo “”;
}
echo “
”.$row[‘name’]."”.$compatibility."
”;[/code]

Don’t worry about the calculation for $distance, I copied that from a page that works. And $maxdistance is defined earlier on the page. I think my problem involves embedding one while statement inside another. If you can either fix my code, or suggest another way to accomplish my task, I would be greatly indebted.

you don’t need these lines i’ve made bold:

$result = mysql_query(SELECT * FROM subjects WHERE sex = ‘1’ ");
$row = mysql_fetch_array($result);
$result1 = mysql_query(SELECT * FROM subjects WHERE sex = ‘0’ ");
$row1 = mysql_fetch_array($result1);

you call them below in a while loop, at first glance i would say they might be the cause…

let me know how you get on,
:wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service