/**
* @param string $nick
* @return array|null
*/
public function getPlayerByNick(string $nick) : ?array{
$query = "SELECT * FROM reports";
$result = $this->connection->query($query);
if($result instanceof \mysqli_result){
$data = $result->fetch_assoc();
$result->free();
var_dump($data);
}
return null;
}
当我执行var_dump时,我只获得表中的第一个用户,但我希望得到所有这些用户。我怎么能这样做?
答案 0 :(得分:-1)
/**
* @param string $nick
* @return array|null
*/
public function getPlayerByNick(string $nick) : ?array{
$query = "SELECT * FROM reports";
$result = $this->connection->query($query);
if($result instanceof \mysqli_result){
while($data = $result->fetch_assoc()){
var_dump($data);
}
$result->free();
}
return null;
}
答案 1 :(得分:-1)
希望这是你的帮助
/**
* @param string $nick
* @return array|null
*/
public function getPlayerByNick(string $nick) : ?array{
$query = "SELECT * FROM reports";
$result = $this->connection->query($query);
if($result instanceof \mysqli_result){
while ($row = $result->fetch_assoc()) {
printf ("%s (%s)\n", $row["nick"]);
}
}
return null;
}