如何在while循环中返回所有元素?

I have a function which grabs logs from database, but whenever im trying to echo this. I am only getting first item.

        function getCoins($odb) {
        $website = new website();
        $SQLGetCoinsLog = $odb -> query("SELECT * FROM `user_logs` ORDER BY `id` DESC");
        while ($getInfo = $SQLGetCoinsLog -> fetch(PDO::FETCH_ASSOC)) {
            $id = $getInfo['id'];
            $userid = $getInfo['userid'];
            $nazwa = $getInfo['nazwa'];
            $cena = $getInfo['cena'];
            $transid = $getInfo['transid'];
            $data = $website->converTimestamp($getInfo['data']);
            $result = '
                <tr class="text-center">
                    <td><a href="https://steamcommunity.com/profiles/'.$userid.'" target="_blank">'.$userid.'</a></td>
                    <td>'.$nazwa.'</td>
                    <td>'.$cena.'PLN</td>
                    <td>'.$transid.'</td>
                    <td>'.$data.'</td>
                </tr>                                           
            ';
        }
        return $result;
        }

Add

$result = "";

At the top of your function to define it (before the while loop), then change your

$result = ' <tr class="text-center"> <td><a href="https://steamcommunity.com/profiles/'.$userid.'" target="_blank">'.$userid.'</a></td> <td>'.$nazwa.'</td> <td>'.$cena.'PLN</td> <td>'.$transid.'</td> <td>'.$data.'</td> </tr> ';

To

$result .= ' <tr class="text-center"> <td><a href="https://steamcommunity.com/profiles/'.$userid.'" target="_blank">'.$userid.'</a></td> <td>'.$nazwa.'</td> <td>'.$cena.'PLN</td> <td>'.$transid.'</td> <td>'.$data.'</td> </tr> ';

Note the dot next to equals, this will add to and not overwrite your variable.

You have a few options.
Echo them in the loop (that does not "return" them) so that really doesn't answer your question, but since it's a table you build, at some point I assume it has to be echoed.

   function getCoins($odb) {
    $website = new website();
    $SQLGetCoinsLog = $odb -> query("SELECT * FROM `user_logs` ORDER BY `id` DESC");
    while ($getInfo = $SQLGetCoinsLog -> fetch(PDO::FETCH_ASSOC)) {
        $id = $getInfo['id'];
        $userid = $getInfo['userid'];
        $nazwa = $getInfo['nazwa'];
        $cena = $getInfo['cena'];
        $transid = $getInfo['transid'];
        $data = $website->converTimestamp($getInfo['data']);
        echo'
            <tr class="text-center">
                <td><a href="https://steamcommunity.com/profiles/'.$userid.'" target="_blank">'.$userid.'</a></td>
                <td>'.$nazwa.'</td>
                <td>'.$cena.'PLN</td>
                <td>'.$transid.'</td>
                <td>'.$data.'</td>
            </tr>                                           
        ';
    }
    }

Or you can build an array with the results:

   function getCoins($odb) {
    $website = new website();
    $SQLGetCoinsLog = $odb -> query("SELECT * FROM `user_logs` ORDER BY `id` DESC");
    while ($getInfo = $SQLGetCoinsLog -> fetch(PDO::FETCH_ASSOC)) {
        $id = $getInfo['id'];
        $userid = $getInfo['userid'];
        $nazwa = $getInfo['nazwa'];
        $cena = $getInfo['cena'];
        $transid = $getInfo['transid'];
        $data = $website->converTimestamp($getInfo['data']);
        $result[] = '
            <tr class="text-center">
                <td><a href="https://steamcommunity.com/profiles/'.$userid.'" target="_blank">'.$userid.'</a></td>
                <td>'.$nazwa.'</td>
                <td>'.$cena.'PLN</td>
                <td>'.$transid.'</td>
                <td>'.$data.'</td>
            </tr>                                           
        ';
    }
    return $result;
    }

//To echo them in main program:
Echo implode("
", getCoins($odb));

Or you can build a string with all the results:

    function getCoins($odb) {
    $website = new website();
    $SQLGetCoinsLog = $odb -> query("SELECT * FROM `user_logs` ORDER BY `id` DESC");
    $result = "";
    while ($getInfo = $SQLGetCoinsLog -> fetch(PDO::FETCH_ASSOC)) {
        $id = $getInfo['id'];
        $userid = $getInfo['userid'];
        $nazwa = $getInfo['nazwa'];
        $cena = $getInfo['cena'];
        $transid = $getInfo['transid'];
        $data = $website->converTimestamp($getInfo['data']);
        $result .= '
            <tr class="text-center">
                <td><a href="https://steamcommunity.com/profiles/'.$userid.'" target="_blank">'.$userid.'</a></td>
                <td>'.$nazwa.'</td>
                <td>'.$cena.'PLN</td>
                <td>'.$transid.'</td>
                <td>'.$data.'</td>
            </tr>                                           
        ';
    }
    return $result;
    }

These variables which you gave the database row's results isn't useful or you cannot benifit them because all of them are local variables or they're deleted and recreated after loop repeated because you created them in the loop, you should create them outside the loop, (e.g.) i think you just need the result so i just add the result outside the loop:-

function getCoins($odb) {
    $website = new website();
    $SQLGetCoinsLog = $odb -> query("SELECT * FROM `user_logs` ORDER BY `id` DESC");
    $result = array();
    while ($getInfo = $SQLGetCoinsLog -> fetch(PDO::FETCH_ASSOC)) {
        $id = $getInfo['id'];
        $userid = $getInfo['userid'];
        $nazwa = $getInfo['nazwa'];
        $cena = $getInfo['cena'];
        $transid = $getInfo['transid'];
        $data = $website->converTimestamp($getInfo['data']);
        array_push($result, '
            <tr class="text-center">
                <td><a href="https://steamcommunity.com/profiles/'.$userid.'" target="_blank">'.$userid.'</a></td>
                <td>'.$nazwa.'</td>
                <td>'.$cena.'PLN</td>
                <td>'.$transid.'</td>
                <td>'.$data.'</td>
            </tr>                                           
        ');
    }
    return $result;
    }