The SQL below is supposed to return two columns, and author's name and the average of all ratings they have had. When I run the page I get the following message:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/domain/public_html/sitename/templates/favourite-authors.php on line 16
Would appreciate anyone's thoughts on where I am going wrong here. Thanks.
<?php
$query = "SELECT bs_authors.name,
bs_authors.linkname,
Avg(bs_reads.rating)
FROM bs_reads
INNER JOIN bs_books
ON bs_reads.book_id = bs_books.book_id
INNER JOIN bs_authors
ON bs_books.author_id = bs_authors.author_id
INNER JOIN bs_users
ON bs_reads.user_id = bs_users.user_id
WHERE bs_reads.status_id = 2
AND bs_users.username = 'defaultUser'
GROUP BY bs_reads.author_id
LIMIT 3";
$result = mysql_query($query);
echo "<ul>";
while($query_data = mysql_fetch_array($result)) {
$author = $query_data[0];
$link = $query_data[1];
$average = $query_data[2];
echo "<li><a href=\"$link\" title=\"$link\">$author</a></li>";
}
echo "</ul>";
?>