[code]
<?php

#-->	connecting to mysql
@mysql_connect("localhost", "...", "...") or die (mysql_error());
mysql_select_db("...") or die(mysql_error());

#-->	updaten of inserten als er ge-vote is op een plaatje
if(isset($_POST['rated']))
{
    #-->   eerst kijken of record al in DB bestaat
    $sql = "SELECT `votes`, `score` FROM `photo_rating` WHERE `img_name`='$_POST[img]'";
    $res = @mysql_query($sql) or die(mysql_error());

    #-->   what's the sql going to be, insert or update
    $sql = (mysql_num_rows($res) == 0) ? "INSERT INTO `photo_rating` SET `img_name`='$_POST[img]', `votes`='1', `score`='$_POST[rated]'" : "UPDATE `photo_rating` SET `votes`=(votes + 1), `score`=(score + '$_POST[rated]') WHERE `img_name`='$_POST[img]'";
    $res = @mysql_query($sql) or die(mysql_error());
}

#-->	allowed img extentions
$alowed_files = array(".gif", ".jpg", ".png");

#-->	opendir, read files, make array
$handle = opendir("images/");
while ($file = readdir($handle))
{
    $len = strlen($file);
    $ext = substr($file, $len -4, $len);
	
    if(in_array($ext, $alowed_files)) {
        $files[] = $file;
   }
}
closedir($handle);

#-->	counting array
$num = count($files);

#-->	fetching get[img] if its there, otherwise rand img
$img = isset($_GET['img']) && is_numeric($_GET['img']) && isset($files[$_GET['img'] -1]) ? $_GET['img'] : rand(1, $num);	

#-->	pulling data form db where img_name is
$sql = "SELECT `votes`, `score` FROM `photo_rating` WHERE `img_name`='".$files[$img-1]."'";
$res = mysql_query($sql) or die(mysql_error());

#-->	opmaken van de stats van de foto
if(mysql_num_rows($res) != 0)
{
    $data = mysql_fetch_assoc($res);

    $score = round($data['score'] / $data['votes'], 1);
    $score = strlen($score) < 2 ? $score .= '.0' : $score;

    $s_img = explode('.', $score);

    switch($s_img[1])
    {
        case 3 :
        case 4 :
        case 5 :
        case 6 :
        case 7 :
            $s_img = $s_img[0].'_5';
            break;

        case 8 :
        case 9 :
            $s_img = ($s_img[0] + 1).'_0';
            break;

        default :
            $s_img = $s_img[0].'_0';
            break;
    }


    $msg ='<img src="rating/'.$s_img.'.gif" alt="'.$s_img.'" /><br /><span style="color:#ccc; font-size:10px;">'.$data['votes'].' stemmen<br />score : '.$score.'</span>';
}
else
{
    $msg = 'no votes yet';
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Photo rating system - by nano</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
body {
	font-family:verdana;
	font-size:12px;
	background-color:#eee;
	text-align:center;}
.img {
	border:1px solid #000;}
.photo {
	text-align:center;
	width:440px;
	margin:0px auto;
	padding:40px;
	background-color:#fff;
	border:1px solid #000;}
</style>
</head>
<body>
<br />
<br />
<div class="photo">
<?php

#-->	echo img en stats
echo '<img class="img" src="images/'.$files[$img-1].'" alt="img" />'."\n<br />\n<br />\n".$msg."\n";

#-->	echo-ing form
echo '<br /><br /><form action="'.$_SERVER['PHP_SELF'].(($img < $num) ? '?img='.($img + 1) : '?img=1').'" method="post">'."\n";
echo '<input type="hidden" name="img" value="'.$files[$img-1].'" />'."\n";
for($i = 0; $i <= 5; $i++)
{
    echo $i.'<input type="radio" name="rated" value="'.$i.'" onclick="submit();" onmouseover="this.checked=true;" onmouseout="this.checked=false;" style="cursor:pointer;" />&nbsp;'."\n";
}
echo "</form>\n";
	
?>
</div>
</body>
</html>
[/code]