Let me give you some insight im doing this to look for compatibility between users.
This is where i gather all the "ratings" the logged in user did.
$myself = "SELECT storyId,username FROM ratings WHERE username<>'Anonymous' AND username='".$session->username."'";
$result = mysql_query($myself);
while ($row = mysql_fetch_array($result)) {
$ratings[] = $row['storyId'];
}
Now im going to go through all the users and see how many times they did the exact same thing my logged in user did.
$sql = "SELECT username FROM users";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
foreach ($ratings as $value) {
$compat = "SELECT id,username FROM ratings WHERE id='".$value."' AND username<>'Anonymous' AND username<>'".$session->username."' AND username='".$row['username']."'";
$result2 = mysql_query($compat);
while ($row2 = mysql_fetch_array($result2)) {
$compatibles[] = $row2['username'];
}
}
}
But the thing is it times out because i poorly made the query but im not sure how to improve it.