PHP: public function getTopPlayers(){ $result = self::getConnection()->query('SELECT name FROM players ORDER BY level DESC LIMIT 5'); while($row = mysql_fetch_array(($result))){ var_dump($row); } } This always say function mysql_fetch_array does not exist What shoud I do?
You should switch over to mysqli functions which is the one php recommends (and is also faster than mysql* functions). Call mysqli_fetch_array.
Now it's without error, but now when I want to get 1,2,3,4 and 5 player, it give me only 1 player PHP: public function getTopPlayers(){ $result = self::getConnection()->query('SELECT name FROM players ORDER BY level DESC LIMIT 5'); while($row = mysqli_fetch_array(($result))){ $top = []; $top[] = $row; foreach($top as $nwm => $key){ $text = "1. " . $key[0] . "2: " . $key[1] . "3: " . $key[2] . "4:" . $key[3] . "5:" . $key[4]; return $text; } } } For $key[1,2,3,4] it's undefined offset But when I var_dump $row it return this PHP: array(2) { [0]=> string(7) "test1" ["name"]=> string(7) "test1"}array(2) { [0]=> string(15) "test2" ["name"]=> string(15) "test2"}array(2) { [0]=> string(15) "test3" ["name"]=> string(15) "test3"}array(2) { [0]=> string(11) "test4" ["name"]=> string(11) "test4"}array(2) { [0]=> string(7) "test5" ["name"]=> string(7) "test5"} What's wrong ?