V
V
Vitaly Gavrilov2017-03-23 15:20:18
PHP
Vitaly Gavrilov, 2017-03-23 15:20:18

Why is the user's avatar not showing through the Steam API?

Good afternoon dear users of this portal. Tell me please. Below I have given the code, which should be the last 15 SteamIDs from my database, requesting their avatar via the Steam API, displaying them on the site in a grid. Everything would be fine, but only the avatars themselves are not displayed. Just white squares.
56d9560081f7481eb6c0abb52c4b0ac9.PNG

<div class="panel panel-default">
  <?php	
    include("db_connect.php");
    $usersData = [];
    $steamIds = [];
        $query = "SELECT steam_id FROM users_profiles ORDER BY `id` DESC limit 15";
        $result = mysql_query($query)or die("MySQL Error");
        if (mysql_num_rows($result) > 0) {
            while ($row = mysql_fetch_assoc($result)) {
                $usersData[$row['steam_id']] = $row;
        $steamIds = $row['steam_id'];
            }
        }

    $url = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=".$steamauth['apikey']."&steamids=" . join(',', $steamIds);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    $result=curl_exec($ch);
    curl_close($ch);
    $steamData = json_decode($result, true);
    
    foreach($steamData['response']['players'] as &$player) {
      $usersData[$player['steamid']]['steam_avatar'] = $player['avatarfull'];
      $usersData[$player['steamid']]['steam_name'] = $player['personaname'];
    }
    
    $chunked = array_chunk($usersData, 3);	
  ?>
    
  <table class="table table-striped table-responsive table-bordered">
  <tbody>
    <?php foreach($chunked as &$chunked_row): ?>
      <tr>
        <?php foreach($chunked_row as &$chunked_cell): ?>
          <td>
            <center>
              <img src="<?= htmlspecialchars($chunked_cell['steam_avatar']); ?>" width="50px" height="50px"/>
              <?= htmlspecialchars($chunked_cell['steam_avatar']); ?>
            </center>
          </td>
        <?php endforeach; ?>
      </tr>
    <?php endforeach; ?>
    </tbody>
  </table>
</div>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Elsevar Rizayev, 2017-03-23
@EllPro

What link is generated on the photo? Provide

R
Rsa97, 2017-03-24
@Rsa97

The src does not need to use htmlspecialchars, which is not critical in this case, but in general, perfectly legitimate ampersands (&) can be converted.
Check your PHP version, prior to version 5.4 the <?= tag was disabled by default and included with <? in php.ini.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question