Theoretic impossiblity

I have a little script (well, a little part of a huge file) that performs a rating function.

I have a database full of images and the all have a “rating” and and amount of “votes”.

I am trying to write a script that will cast new votes, however, whats seems to be quite simple math is turning into a bit of an issue. Take a look:

$rating = $_GET['rating'];
  $id = $_GET['id'];
  $sql = 'select * from images where id = '.$id.' limit 1'; 
  $result = $db->query($sql);
  $total = $result->num_rows; 
  while ($row = $result->fetch_assoc()) {
   $currentrating = $row['rating'];
   $currentvotes = $row['votes'];
  }
  $db->close();
  $total = $currentvotes*$currentrating;
  $total = $total+$rating;
  $newamountofvotes = $currentvotes+1;
  $newrating = $total/$currentvotes;
  mysql_pconnect ($hostname, $username, $password); 
  mysql_select_db ($database); 
  mysql_query ("UPDATE images SET rating = '$newrating' , votes = '$newamountofvotes' WHERE id = '$id'"); 
 
  echo "current rating: '$currentrating'<br>";
  echo "current amount of votes: '$currentvotes'<br>";
  echo "new vote: '$rating'<br>";
  echo "new amount of votes: '$newamountofvotes'<br>";
  echo "new rating: '$newrating'<br>";

Problem is, say i keep casting a new vote of 25 upon a current rating of 6, numerous times. It will rise until about 13, then start tyo go down again, would it not just keep getting closer and closer to 25? (well, it wil never get there obviously)

Any ideas? Heres a link to the script:
http://www.akacom.com/mcveysykes/list.php
The variables are just GET vars so try:
[COLOR=#5a3d1b]http://www.akacom.com/mcveysykes/list.php?id=3&rating=25[/COLOR]
[COLOR=#5a3d1b][/COLOR]
[COLOR=#5a3d1b]Also, i’m sure there is a h undred differnt better ways to do this than querying twice, so if you want to slap anything together, feel free, I’m not too woried as this is pretty low traffic.[/COLOR]