I'm trying to get only the Top1 Player in my Database and i use this code that doesn't works! EVENT: PHP: public function getRankingTest() { $records = [ ]; try { $prepare = $this->provider->database->prepare ( "SELECT * FROM `pvp_stats` ORDER BY `kills` DESC LIMIT 3"); $result = $prepare->execute (); if ($result instanceof \SQLite3Result) { while ( $data = $result->fetchArray ( SQLITE3_ASSOC ) ) { $records [] = $data; } $result->finalize (); } } catch ( \Exception $e ) { $this->plugin->printError($e) ; } return $records; } COMMAND: PHP: case "teste1": $ranking = $this->getRankingTest(); if (count ( $ranking ) == 1) { $top1 = $ranking [0] ["name"]; $sender->sendMessage("top 1 best player: ".$top1.""); } break; when i try to use the command, this is the error: 17.07 13:20:10 [Server] Server thread/INFO An unknown error occurred while attempting to perform this command 17.07 13:20:10 [Server] Server thread/CRITICAL Unhandled exception executing command 'teste1' in teste1: Cannot use object of type mysqli_result as array 17.07 13:20:10 [Server] Server thread/CRITICAL Error: "Cannot use object of type mysqli_result as array" (EXCEPTION) in "Main" at line 122 Line 122: PHP: if (count ( $ranking ) == 1) { i don't know how to fix, i'm bad at DATABASE can anyone help me, and make an example? Thk Sorry for my english..
Thanks for the good explaining, but there's one problem: I can't read your code, it's pink on grey background (in the dark theme), close to unreadable, please consider using code blocks ([php]Put your code here[/php]) for posting code
Apparently you're mixing up MySQL with SQLite. It gives an error about MySQL while you're checking for an SQLite3 result.
Like so: PHP: public function getRankingTest() { $records = [ ]; try { $prepare = $this->provider->database->prepare ( "SELECT * FROM `pvp_stats` ORDER BY `kills` DESC LIMIT 3"); $result = $prepare->execute (); } catch ( \Exception $e ) { $this->plugin->printError($e) ; } return $records; } ?
When i do this, i try to run the command "/teste1" and doesn't do anything, and doesn't have any error on Console :/