$ratings=Array("- select -", "Poor", "Fair", "Good", "Very good", "Excellent");
if ($_GET[ID]) {
$connection = mysql_connect($host,$db_username,$db_pass);
mysql_selectdb($db_name);
$result = mysql_query("SELECT * FROM rating WHERE ID=$_GET[ID]");
$fields = mysql_fetch_row($result);
if (!$fields[0]) {
$num_rows = mysql_result(mysql_query("SELECT COUNT(ID) FROM rating"),0);
if ($num_rows <= $max_rows) {
mysql_query("INSERT INTO rating VALUES ($_GET[ID],0,0,'0.0.0.0')");
$rating = 0;
$votes = 0;
}
else die("Error: Max rows reached.");
}
else {
$rating = $fields[2];
$votes = $fields[1];
}
if ($_POST[your_rating] > 0 and $fields[3] != $REMOTE_ADDR) {
$your_rating = $_POST[your_rating] * 10;
$votes++;
$rating = ($fields[2]*$fields[1]+$your_rating)/$votes;
mysql_query("UPDATE rating SET votes = $votes, rating = $rating, last_ip = '$REMOTE_ADDR' WHERE ID=$_GET[ID]");
}
$image = (round($rating/50,1)*50)."-star.gif";
$note = number_format($rating/10, 1);
echo "<form action=\"rating.php?ID=".$_GET[ID]."\" method=\"POST\">
<font size=2 face=Verdana><B>Rating:</B></FONT> <img src=\"$image\" alt=\"Rating: $note\" align=\"middle\"> <font size=1 face=Verdana color=RED>($note from $votes votes)</font>
<select name=\"your_rating\" style=\"font-size: 8pt\">
<option value=\"0\" selected>$ratings[0]
";
for ($i=5; $i>=1; $i--) {
echo "<option value=\"$i\">$ratings[$i]\n";
}
}
else die("Error: ID not set!");
?>
</select>
<input type="submit" value="Rate!" style="font-size: 8pt">
</form>
</font>
</center>
</body>
<html>