0

I'm trying to display donators list in the php page. All info of donators is on database. There is a php code:

$apikey = 'my_apikey_here';

$host = 'db_host';
$user = 'db_user';
$password = 'db_user_pw';
$database = 'db';

$connection = new mysqli($host, $user, $password, $database);
if (mysqli_connect_error()) 
{
    die('Error connect to Batabase: (' . mysqli_connect_errno() . ') '
        . mysqli_connect_error());
}

$query = "SELECT * FROM `donate_top_donors` ORDER BY amount DESC";
$result = $connection->query($query);


while($row = mysqli_fetch_array($result)) 
{

    $id = $row['id'];
    $user = $row['user'];
    $steamid64 = $row['steamid64'];
    $amount = $row['amount'];
    $date = $row['unix_date'];



    $response = file_get_contents("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=" . $apikey . "&steamids=" . $steamid64);


    $json = json_decode($response, true); 

    $avatar = $json['response']['players'][0]['avatar'];
    $personaname = $json['response']['players'][0]['personaname'];

    echo "
        <div class='col'>
            <div class='donation-container'>
                <div class='Column Column_narrow'>";
                if(isset($personaname))
                {
                    echo "<a href='https://steamcommunity.com/profiles/".$steamid64."' target='_blank'><img src='".$avatar."' alt='profile avatar'></a>

                    </div>
                    <div class='Column Column_fluid'>
                    <a href='https://steamcommunity.com/profiles/".$steamid64."' target='_blank'>".$personaname."</a>";
                }
                else
                {
                    echo "<a href='https://steamcommunity.com/profiles/".$steamid64."' target='_blank'><img src='https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/fe/fef49e7fa7e1997310d705b2a6158ff8dc1cdfeb.jpg' alt='profile avatar'></a>

                    </div>
                    <div class='Column Column_fluid'>
                    <a href='https://steamcommunity.com/profiles/".$steamid64."' target='_blank'>".$user."</a>";
                }


                echo "<p><strong><span style='font-size: 15px;'>.".$amount." €</span></strong></p>
            </div>
            </div>
        </div>";
}

DB screenshoot: https://image.prntscr.com/image/wVIrQWf-ReSB1YmaDZuPsQ.png

Web page screenshoot: https://image.prntscr.com/image/ATa6bbL5T1ydiIMfF3vGcw.png

Seems that everything is good, but the one big problem, that i have waited few minutes while web page loading. I think the reason why this happens it's because

$response = file_get_contents("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=" . $apikey . "&steamids=" . $steamid64);

calling in cycle while but i have no idea how to do it another way. Any suggestions please

Thanks.

inGame
  • 17
  • 6

1 Answers1

0

Find in steam documentation way to get multiple users at once. Param steamids suggests that it is possible.

If it is possilbe - load all results from DB to variable, and collect steam id's, make one query to steam api, merge results and in second foreach display to user.

If it isn't posssible - you must store these values in cache (memcached/redis/database/file, NOT _SESSION)

bato3
  • 2,695
  • 1
  • 18
  • 26