I' m using the following code to get the desired details,that is, all the books that have the highest total count in order to show the most trending/popular books present in a website. The total column depicts the no. of times a particular book had been viewed by an user of the website. Here is the code`
<?php
include("connection.php");
global $con;
$sql1= "SELECT book FROM vi_views ORDER BY total DESC LIMIT 3";
$query1= mysqli_query($con,$sql1);
if (!$query1)
{
printf("Error: %s
", mysqli_error($con));
exit();
}
$obj1=mysqli_fetch_array($query1,MYSQLI_BOTH);
$row1=mysqli_num_rows($query1);
if ($row1>0)
{
echo var_dump($obj1);
}
?>
Here is a look of how my table looks
Table:vi_views
id book course date total
1 book1 null dd//mm/yy 3
2 null course1 dd/mm/yy 1
3 book2 null dd/mm/yy 8
and so on....
The problem is that the query is working but only the first record according to the query is shown, that is, book2 in this case and no more books are showing. where I'm lacking in my code please tell...