$max) { $max = $row[0]; }
$quotes[($row[1])] = $row[0];
}
$sql = 'SELECT u.user_id, r.rating_change, r.quote_id, r.user_id AS rater FROM ratings AS r, quotes AS u WHERE u.quote_id = r.quote_id';
$qr = array();
$res = mysql_query($sql);
while ($row = mysql_fetch_array($res)) {
if (!isset($qr[($row['quote_id'])])) {
$qr[($row['quote_id'])] = array('for'=>array(),'against'=>array());
}
$user =& $users[($row['user_id'])];
if ($row['rating_change'] == 0) {
$user += 0;
} elseif ($row['rating_change'] > 0) {
$user += 1;
$qr[($row['quote_id'])]['for'][] = $row['rater'];
} else {
$user -= 1;
$qr[($row['quote_id'])]['against'][] = $row['rater'];
}
}
foreach ($qr as $quote => $rankings) {
$for = count($rankings['for']);
$against = count($rankings['against']);
$total = $for + $against;
if ($for == 0) {
foreach ($rankings['against'] as $uid) {
$users[$uid] += 0.5;
}
} elseif ($against == 0) {
foreach ($rankings['for'] as $uid) {
$users[$uid] += 0.5;
}
} else {
$forscore = $for/$total - 0.5;
$againstscore = $against/$total - 0.5;
foreach ($rankings['for'] as $uid) {
$users[$uid] += $forscore;
}
foreach ($rankings['against'] as $uid) {
$users[$uid] -= $againstscore;
}
}
}
foreach ($users as $uid => $user) {
#echo $uid.' ==> '.$user.' == > '.(10*$user*(1+$quotes[$uid])/pow($max,2)).'
';
}
$nusers = array();
$sql = 'SELECT u.user_id, r.rating_change FROM ratings AS r, quotes AS u WHERE u.quote_id = r.quote_id';
$res = mysql_query($sql);
while ($row = mysql_fetch_array($res)) {
$user =& $nusers[($row['user_id'])];
if ($row['rating_change'] == 0) {
$base = 0;
} elseif ($row['rating_change'] > 0) {
$base = 1;
} else {
$base = -1;
}
$base *= ($users[($row['user_id'])]+10)/10;
$user += $base;
}
$sql = 'SELECT COUNT(*) FROM users';
$res = mysql_query($sql);
$row = mysql_fetch_array($res);
$cusers = $row[0];
foreach ($qr as $quote => $rankings) {
$for = count($rankings['for']);
$against = count($rankings['against']);
$total = $for + $against;
if ($for == 0) {
foreach ($rankings['against'] as $uid) {
$nusers[$uid] += 0.5;
}
} elseif ($against == 0) {
foreach ($rankings['for'] as $uid) {
$nusers[$uid] += 0.5;
}
} else {
$forscore = $for/$total - 0.5;
$againstscore = $against/$total - 0.5;
foreach ($rankings['for'] as $uid) {
$nusers[$uid] += $forscore;
}
foreach ($rankings['against'] as $uid) {
$nusers[$uid] -= $againstscore;
}
}
}
#echo '