I have a method which queries top 5 items from selected table and adds each row to a list. When i try to make an ordered list from this method, it lists 10 items not 5. One correct line and one blank line on each iteration. I've tried both a method in class and a function outside of the class but result is same.
Here is my method:
/**
* @return array
*/
public function top_list(): array {
/* @var mysqli_result $result */
$sql = "SELECT name FROM users ORDER BY performance DESC LIMIT 5";
$result = self::$database->query($sql);
if (!$result) {
exit("Database query failed.");
}
$list = [];
while ($record = $result->fetch_assoc()) {
$list[] = $record;
}
$result->free();
return $list;
}
and here is my ordered list:
$user = new User();
foreach ($user->top_list() as $item) {
echo "<li>";
echo $item["name"];
echo "<li />";
}