".$lowest_score." AND live=1 ORDER BY RAND() LIMIT 1"; if (!$result1=mysql_query($sql,$db_connection)){echo "ERROR1";} if($row = mysql_fetch_array($result1)){ $image[]=$row; } $sql = "SELECT * FROM `rating_images` WHERE `score`>".$lowest_score." AND ABS(`score` - ".$image[0]['score'].")<".$max_score_diff." AND live=1 ORDER BY RAND() LIMIT 1"; if (!$result1=mysql_query($sql,$db_connection)){echo "ERROR2";} if($row = mysql_fetch_array($result1)){ $image[]=$row; } } //Generate a random key for this vote $key = randomString(); //Add this vote to the db $sql = "INSERT INTO `rating_votes` (`key`, `image1`, `image2`) VALUES ('$key',".$image[0]['id'].",".$image[1]['id'].")"; if (!$result2=mysql_query($sql,$db_connection)){} //Find out if this is a report if ($_GET[report]){ $old_key = mysql_real_escape_string(trim($_GET['key'])); $report = trim($_GET['report']); //Find the images reported on $sql = "SELECT * FROM rating_votes WHERE `key`='$old_key'"; if (!$result=mysql_query($sql,$db_connection)){} while($row = mysql_fetch_array($result)){ $image1_id=$row['image1']; $image2_id=$row['image2']; } if ($report==1) { $sql = "INSERT INTO `rating_reports` (`image`, `reason`) VALUES ('$image1_id',1)"; if (!$result2=mysql_query($sql,$db_connection)){ if ($debug_mode) {die('Error: ' . mysql_error());} } } if ($report==2) { $sql = "INSERT INTO `rating_reports` (`image`, `reason`) VALUES ('$image2_id',1)"; if (!$result2=mysql_query($sql,$db_connection)){ if ($debug_mode) {die('Error: ' . mysql_error());} } } //remove this vote $sql = "DELETE FROM rating_votes WHERE `key`='$old_key' OR `time` < DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 HOUR)"; if (!mysql_query($sql,$db_connection)){} } //Find out if this is a vote if ($_GET[vote]){ $old_key = mysql_real_escape_string(trim($_GET['key'])); $vote = trim($_GET['vote']); //Find the images voted on $sql = "SELECT * FROM rating_votes WHERE `key`='$old_key'"; if (!$result=mysql_query($sql,$db_connection)){} while($row = mysql_fetch_array($result)){ $image1_id=$row['image1']; $image2_id=$row['image2']; } //Find the scores of those images $sql = "SELECT * FROM rating_images WHERE `id`=$image1_id"; if (!$result=mysql_query($sql,$db_connection)){} while($row = mysql_fetch_array($result)){ $image1_score=$row['score']; } $sql = "SELECT * FROM rating_images WHERE `id`=$image2_id"; if (!$result=mysql_query($sql,$db_connection)){} while($row = mysql_fetch_array($result)){ $image2_score=$row['score']; } //Calculate expected scores: $image1_expectation = 1/(1+pow(10,$image2_score-$image1_score)); $image2_expectation = 1 - $image1_expectation; //adjust scores if($vote == 1) { $image1_score += $kFactor*(1-$image1_expectation); $image2_score -= $kFactor*$image2_expectation; $sql = "UPDATE `rating_stats` SET `left`=`left`+1 WHERE `votes`=1"; if (!$result=mysql_query($sql,$db_connection)){} } if($vote == 2) { $image2_score += $kFactor*(1-$image2_expectation); $image1_score -= $kFactor*$image1_expectation; $sql = "UPDATE `rating_stats` SET `right`=`right`+1 WHERE `votes`=1"; if (!$result=mysql_query($sql,$db_connection)){} } //Update scores $sql = "UPDATE `rating_images` SET `score`=$image1_score WHERE `id`=$image1_id"; if (!$result=mysql_query($sql,$db_connection)){} $sql = "UPDATE `rating_images` SET `score`=$image2_score WHERE `id`=$image2_id"; if (!$result=mysql_query($sql,$db_connection)){} //remove this vote $sql = "DELETE FROM rating_votes WHERE `key`='$old_key' OR `time` < DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 1 HOUR)"; if (!mysql_query($sql,$db_connection)){} } ?>
Click on the photo you think is the best one.
'; echo 'SKIP VOTE' . "\n"; ?>
'; echo '' . "\n"; ?>
Photo description:
' . $the_image['name'] . "\n"; ?>
Categories:
\n"; } ?>
Change category: