Hi,
I am trying to write a script that will go through and tally a song rating based on 4 reviewer's scores. I have it designed to only tally a score if it has at least 4 reviews. The issue is that it will cruise along just fine until it gets to a song that actualy does have 4 reviews, it will then tally up the score but then it will give a "not a valid resource" error on the next.
like this if the third song has four reviews:
01 is 0
02 is 0
03 is 9.76
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in updateNoVotesOnce.php on line 6
$getrevs = "SELECT songid FROM songs";
$rs = mysql_query($getrevs, $conn);
if(mysql_num_rows($rs)) {
while ($row = mysql_fetch_array ($rs, MYSQL_ASSOC)) {
$songid = $row['songid'];
$revrating = 0;
$sql5 = "SELECT COUNT(review) AS count FROM reviews WHERE songid = '$songid'";
$result5 = mysql_query($sql5);
$revc= mysql_result($result5, 0);
if ($revc >= 4){
$getRev = "SELECT AVG(ro) AS ro, AVG(ror) AS ror, AVG(rs) AS rs, AVG(rp) AS rp FROM reviews WHERE songid = '$songid'";
$grating = mysql_query($getRev, $conn) or die(mysql_error());
$rowr = mysql_fetch_array($grating);
$ro = ($rowr['ro']);
$ror = ($rowr['ror']);
$rs = ($rowr['rs']);
$rp = ($rowr['rp']);
$revrating = ($ro + $ror + $rs + $rp);
$revrating = ($revrating / 4);
$revrating = number_format($revrating, 2);
}
else{
$revrating = 0;
}
echo"$songid is $revrating<br>";
}
}
Any help is much appreciated.