= 1){ //connecting to the database to get some information $query = mysql_query("SELECT totalvotes,totalvotepoints FROM games WHERE gameid =". $id)or die(" Error: ".mysql_error()); $numbers = mysql_fetch_assoc($query); $count = $numbers['totalvotes']; //how many votes total $current_rating = $numbers['totalvotepoints']; //total number of rating added together and stored $sum = $rating+$current_rating; // add together the current vote value and the total vote value $tense = ($count==1) ? "vote" : "votes"; //plural form votes/vote $newrating = $current_rating + $rating; // checking to see if the first vote has been tallied // or increment the current number of votes ($sum==0 ? $added=0 : $added=$count+1); // Check cookie to see if the user has already rated this item $alreadyrated = $_COOKIE['rated']; if(strpos($alreadyrated,"|$id|")!==false){ //$voted="yes!"; echo 'already_voted'; } else { $update = "UPDATE games SET totalvotes=totalvotes+1, totalvotepoints=".$newrating." WHERE gameid=".$id; $result = mysql_query($update) or die(mysql_error()); $alreadyrated.="|$id|"; setcookie("rated",$alreadyrated,time()+604800,'/',$domain,false); //mysql_query("INSERT INTO ratings (rating_id,rating_number,ip_addr) VALUES ('$id','$rating','".$_SERVER['REMOTE_ADDR']."')") or die(mysql_error()); $total = 0; $rows = 0; $sel = mysql_query("SELECT totalvotepoints, totalvotes FROM games WHERE gameid = ".$id); while($data = mysql_fetch_assoc($sel)){ $total = $data['totalvotepoints']; $divident = $data['totalvotes']; $rows++; } $perc = ($total/$divident) * 20; echo round($perc,2); //echo round($perc/5)*5; } } } // IF JAVASCRIPT IS DISABLED if($_GET){ $id = escape($_GET['id']); $rating = (int) $_GET['rating']; if($rating <= 5 && $rating >= 1){ //connecting to the database to get some information $query = mysql_query("SELECT totalvotes,totalvotepoints FROM games WHERE gameid=$id ")or die(" Error: ".mysql_error()); $numbers = mysql_fetch_assoc($query); $count = $numbers['totalvotes']; //how many votes total $current_rating = $numbers['totalvotepoints']; //total number of rating added together and stored $sum = $rating+$current_rating; // add together the current vote value and the total vote value $tense = ($count==1) ? "vote" : "votes"; //plural form votes/vote // checking to see if the first vote has been tallied // or increment the current number of votes $sum==0 ? $added=0 : $added=$count+1; // Check cookie to see if the user has already rated this item $alreadyrated = $_COOKIE['rated']; if(strpos($alreadyrated,"|$id|")!==false){ $voted="yes!"; echo 'already_voted'; } else { $update = "UPDATE games SET totalvotes=totalvotes+1, totalvotepoints=totalvotepoints+$rating WHERE gameid=$id"; $result = mysql_query($update); $alreadyrated.="|$id|"; setcookie("rated",$alreadyrated,time()+604800); //mysql_query("INSERT INTO ratings (rating_id,rating_number,ip_addr) VALUES ('$id','$rating','".$_SERVER['REMOTE_ADDR']."')") or die(mysql_error()); $total = 0; $rows = 0; $sel = mysql_query("SELECT totalvotepoints, totalvotes FROM games WHERE gameid = ".$id); while($data = mysql_fetch_assoc($sel)){ $total = $data['totalvotepoints']; $divident = $data['totalvotes']; $rows++; } $perc = ($total/$divident) * 20; echo round($perc,2); //echo round($perc/5)*5; } } } ?>