I'm trying to get information from a database table where the url($address)
and it's ratings($rate) are stored ($rate is a number from 1-10).
Now I tried many things to get the average,minimum and maximum, but I'm still stuck due to following error:
Invalid use of group function
Warning: Supplied argument is not a valid MySQL result resource...
In the script I get two times the same error.
Any help would be very welcome indeed!
$query = "SELECT address, MAX( rate ) AS 'rate' FROM statistiek GROUP BY address";
$result = mysql_query($query);
echo mysql_error();
while ($row = mysql_fetch_array($result)){
$rate = $row['rate'];
$address = $row['address'];
echo "<table border=\"1\" width=\"100%\"><tr><th>Highest rate</th><th>Worst rates</th><th>Good Sites</th><th>Bad sites</th></tr>";
echo "<td><a href=\"{$row['address']}\">{$row['address']}</a> Rate:{$row['rate']}</td>";
}
$query2 = "SELECT address, MIN( rate ) AS 'rate2' FROM statistiek GROUP BY address";
$result2 = mysql_query($query2);
echo mysql_error();
while ($row = mysql_fetch_array($result2)){
$rate2 = $row['rate2'];
/Here I get error number one/
$address = $row['address'];
echo "<td><a href=\"{$row['address']}\">{$row['address']}</a> Rate:{$row['rate2']}</td>";
}
$query3 = "SELECT address,AVG ( rate ) AS 'rate3' FROM statistiek WHERE AVG( rate )<6 GROUP BY '$rate3'";
$result3 = mysql_query($query3);
echo mysql_error();
/Here I get error number two/
while ($row = mysql_fetch_array($result3)){
$rate3 = $row['rate3'];
$address = $row['address'];
echo "<td><a href=\"{$row['address']}\">{$row['address']} Rate:{$row['rate3']}</a></td>";
}
$query4 = "SELECT address,AVG( rate ) AS 'rate4' FROM statistiek WHERE AVG( rate )>6 GROUP BY '$rate4'";
$result4 = mysql_query($query4);
echo mysql_error();
while ($row = mysql_fetch_array($result4)){
$rate4 = $row['rate4'];
$address = $row['address'];
echo "<td><a href=\"{$row['address']}\">{$row['address']}</a> Rate:{$row['rate4']}</td></tr></table>";
}
?>