Får følgende fejlmeddelelse:
Warning: Division by zero in /home/www/inheaven.awardspace.com/game.php on line 50
Warning: Cannot modify header information - headers already sent by (output started at /home/www/inheaven.awardspace.com/game.php:50) in /home/www/inheaven.awardspace.com/game.php on line 98
<?
$gid = $_GET['id'];
$rategame = $_GET['rate'];
include ("config.php");
$sql = mysql_fetch_array(mysql_query("SELECT * FROM games WHERE id = $gid"));
$rate = $sql[rate];
$ratenr = $sql[ratenr];
if (empty($rate)) {
$rate = 0;
$ratenr = 1;
}
elseif (isset($rategame)) {
$rate = 0;
$ratenr = 0;
}
$rate2 = $rate + $rategame;
$ratenr2 = $ratenr + 1;
$avg = $rate2 / $ratenr2;
$avg2 = number_format($avg,2);
$ratewidth = $avg2 * 14;
$ratem = $sql[ratem];
$ratemnr = $sql[ratemnr];
if (empty($ratem)) {
$ratem = 0;
$ratemnr = 1;
}
if (empty($ratem)) {
$ratem = 0;
$ratemnr = 1;
}
elseif (isset($rategame)) {
$ratem = 0;
$ratemnr = 0;
}
$ratem2 = $ratem + $rategame;
$ratenmr2 = $ratemnr + 1;
$avgm = $ratem2 / $ratemnr2;
$avgm2 = number_format($avgm,2);
$ratey = $sql[ratey];
$rateynr = $sql[rateynr];
if (empty($ratey)) {
$ratey = 0;
$rateynr = 1;
}
elseif (isset($rategame)) {
$ratey = 0;
$rateynr = 0;
}
$ratey2 = $ratey + $rategame;
$rateynr2 = $rateynr + 1;
$avgy = $ratey2 / $rateynr2;
$avgy2 = number_format($avgy,2);
if (empty($rategame)) {
$rategame = $_COOKIE['s$gid'];
}
if (empty($rategame)) {
$showrater = "<span class='rate'>
<span class='current-rating' style='width: $ratewidth px'> </span>
<span><a href='game.php?id=$gid&rate=1' title='Rate it 1' class='1'>1</a></span>
<span><a href='game.php?id=$gid&rate=2' title='Rate it 2' class='2'>2</a></span>
<span><a href='game.php?id=$gid&rate=3' title='Rate it 3' class='3'>3</a></span>
<span><a href='game.php?id=$gid&rate=4' title='Rate it 4' class='4'>4</a></span>
<span><a href='game.php?id=$gid&rate=5' title='Rate it 5' class='5'>5</a></span>
</span>";}
if (isset($_COOKIE["s$gid"])){
$showrater = "<span class='rate'>
<span class='current-rating' style='width: $ratewidth px' title='Current rating: $avg2'> </span>
</span>";
}
if (isset($_GET["rate"]) && empty($_COOKIE["s$gid"])){
include ("config.php");
mysql_query("UPDATE games SET rateavg = $avg2, ratenr = ratenr+1, rate = rate+$rategame, ratemavg = $avgm2, ratemnr =
ratemnr+1, ratem = ratem+$rategame, rateyavg = $avgy2, rateynr = rateynr+1, ratey = ratey+$rategame WHERE id = '$gid'") or
die(mysql_error());
setcookie("s$gid", "$rategame", time()+604800);
}
?>
...koden skulle tjekke om man har stemt før (cookie) og hvis man har så kan man ikke igen.
Når man stemmer skal den så (udover at putte informationerne ind i tabellen) regne et gennemsnit ud og også smide det i tabellen, og så lavede jeg lidt kode til at forkorte tallene og for at undgå "division by zero"
nogen der kan hjælpe?