I have t table which contains views from books:
ID UserID TIME BookID
1 2 (timedate) 1
1 3 (timedate) 1
1 54 (timedate) 1
1 4 (timedate) 2
1 5 (timedate) 2
much more ....
I been trying to get a query which counts the number of views of the books and list them from highest to lowest.
I want to do this so I can display 5 books with the highs amount of views in the past month.
Non of the given are working!
Im putting it through a while loop if that helps.
$gethotbookq = mysqli_query($con,"select BookID, count(*) as views
from `BOOKS_views`
where `TIME` >= '2014-05-01 00:00:00' and `TIME` < '2014-06-01 00:00:00'
group by BookID
order by views desc
limit 5") or die();
while($gethotbook = mysql_fetch_array($gethotbookq))
{
$bookid = $gethotbook['BookID'];
}