0

I try to get the 5 most-watched Movies from my database and echo the output. Below are some of the related lines:

$sqlGetTop5 = "SELECT TVSeries_ID,COUNT(TVSeries_ID) AS Frequency FROM TVSeries_Watched GROUP BY TVSeries_ID ORDER BY Frequency DESC LIMIT 5";
$ResultGetTop5 = $DBConnect->query($sqlGetTop5);
            
while($row = $ResultGetTop5->mysqli_fetch_array()){
                
      echo $row['Frequency'];
                
}

But when I execute the query, "Fatal error: Uncaught Error: Call to undefined method mysqli_result::mysqli_fetch_array() in..." has occurred. I have no idea how to solve it. What is the problem and how to solve this issue?

Hingusan
  • 43
  • 6
  • The `query` method returns `FALSE` on fail. It looks like the SQL is not valid. Can you check your `GROUP BY` – DanLewis Jun 17 '21 at 10:05
  • How is `$DBConnect` defined? Most probably the db connection failed. – digijay Jun 17 '21 at 10:07
  • `mysqli_fetch_array` is not a method of `mysqli_result`. Check the manual for the right syntax – Dharman Jun 17 '21 at 10:15
  • 1
    If you are only starting to learn PHP then you should learn PDO instead of mysqli. PDO is much easier and more suitable for beginners. Start here https://phpdelusions.net/pdo & https://websitebeaver.com/php-pdo-prepared-statements-to-prevent-sql-injection – Dharman Jun 17 '21 at 10:16

1 Answers1

1

From the (very helpful) PHP docs:

$DBConnect->query($sqlGetTop5) returns false if the query failed. This means something is wrong with your query. Though I am no SQL expert GROUD BY ORDER BY looks a little weird to me.

Einliterflasche
  • 473
  • 6
  • 18