0

I'm trying to get an array from a server class and processed to the client. The problem is that im only recieving the first result from the database? I don't know how to get all the results from the database into the array and I would like to have a loop on the client side that goes through the array.

Database class:

function getPlayers($teamid) {
    $q = "SELECT * FROM view_players WHERE teamid = '$teamid'";
    $result = mysqli_query ( $this->connection, $q );
    /* Error occurred, return given name by default */
    if (! $result || (mysqli_num_rows ( $result ) < 1)) {
        return NULL;
    }
    /* Return result array */
    $dbarray = mysqli_fetch_array ( $result );
    return $dbarray;
}

Session class:

function getPlayers($teamid) {
    global $database;

    $players = $database->getPlayers ( $teamid );
    return $players;
}

Client class:

$players = $session->getPlayers($session->teamid);

while (list($key, $value) = each($players)) {
        echo "Key: $key; Value: $value<br />\n";
}

Thanks in advance for your time.

Kingfox
  • 129
  • 14
  • 1
    RTFM: http://php.net/manual/en/mysqli-result.fetch-array.php `... Fetch a result **row** ... `. **ROW**, one single solitary row... – Marc B Aug 22 '16 at 14:28
  • 1
    mysqli_fetch_all will return all the results in an array style, you can check it here: http://php.net/manual/en/mysqli-result.fetch-all.php – Salvador P. Aug 22 '16 at 14:31
  • 1
    This was very helpfull and solved my problem http://stackoverflow.com/questions/22527465/fetch-all-results-from-database-using-mysqli/22527518#22527518 – Kingfox Aug 22 '16 at 14:40

0 Answers0