2016-03-01 154 views
2
<?php 
function username($uuid) { 
    $username = file_get_contents("https://us.mc-api.net/v3/name/$uuid/json"); 
    $data = json_decode($username, true); 
    return $data['name']; 
} 
     while($row = mysql_fetch_assoc($result)){ 
      $uuid = $row['UUID']; 
      $kills = $row['KILLS']; 
      $deaths = $row['DEATHS']; 
      echo 
      "<tr> 
       <td> 
       <img src='http://cravatar.eu/head/$uuid/64.png'/> 
       " . username($uuid) . " 
       <td>$kills</td> 
       <td>$deaths</td> 
      </tr>\n"; 
      } 

我最近開始爲了網頁排行榜學習php。我已經得到了一個工作版本,雖然這部分正在困擾着我。我在這裏做錯了什麼? [php]

我試圖在顯示頭像後得到它,它也顯示了掛在uuid上的用戶名。頭像只是不是用戶名部分。 這是這個代碼的預覽:https://gyazo.com/de6f92aa637c0f43f560e4ddfb986a0d 我搜索了一些常見的問題,但我找不到任何東西。任何幫助,將不勝感激。

+0

你能確認'json_decode($ username,true)'是否真的會給你返回一些東西嗎? – roullie

+1

你會得到什麼錯誤? –

+0

@roullie這是一個API,所以我猜?每當我將它輸入到瀏覽器中時,它都能正常工作。 沒有錯誤,它只是不顯示用戶名。 – iVersion

回答

0

你沒有關閉在行開始時打開的<td>。應該是這樣的:

  <td> 
      <img src='http://cravatar.eu/head/$uuid/64.png'/> 
      " . username($uuid) . "</td> 
+0

關閉它,雖然這不是問題。 – iVersion

相關問題