-1
私はworldoftanks APIサーバーからのデータを表示するPHPスクリプトを持っています。私はこのデータをテーブルに表示していますので、「Recruit」というユーザーの近くにイメージを追加したいと思います。jquery指定されたテキストの近くにテーブルTDの画像を追加する方法
これは、テーブルのための私のjavascriptです:
<script type="text/javascript">
$(document).ready(function(){
$.ajax({
type: "POST",
url: "clan_info.php",
success: function(data){
var htmlString = '<table cellpadding="0px" class="menu1"><tr><th>Username</th><th>Rank</th><th>PR</th><th>BTL</th><th>W/B</th><th>E/B</th><th>Days</th></tr>';
var clanData = JSON.parse(data);
i = 0;
for(userID in clanData){
userData = clanData[userID];
var extraClass = '';
if(i < 3) {
extraClass = 'class="rank' + (i+1) + '"';
}
htmlString += '<tr>';
htmlString += '<td '+extraClass+'><a href="http://worldoftanks.eu/en/community/accounts/' + userData['id'] +'" target="_blank">' + userData['name'] + '</a></td>';
htmlString += '<td '+extraClass+'><a href="http://worldoftanks.eu/en/community/accounts/' + userData['id'] +'" target="_blank">' + userData['role'] + '</a></td>';
htmlString += '<td '+extraClass+'><a href="http://worldoftanks.eu/en/community/accounts/' + userData['id'] +'" target="_blank">' + userData['rating'] + '</a></td>';
htmlString += '<td '+extraClass+'><a href="http://worldoftanks.eu/en/community/accounts/' + userData['id'] +'" target="_blank">' + userData['battles'] + '</a></td>';
htmlString += '<td '+extraClass+'><a href="http://worldoftanks.eu/en/community/accounts/' + userData['id'] +'" target="_blank">' + userData['w_p_b'] + '</a></td>';
htmlString += '<td '+extraClass+'><a href="http://worldoftanks.eu/en/community/accounts/' + userData['id'] +'" target="_blank">' + userData['xp_p_b'] + '</a></td>';
htmlString += '<td '+extraClass+'><a href="http://worldoftanks.eu/en/community/accounts/' + userData['id'] +'" target="_blank">' + userData['days'] + '</a></td>';
htmlString += '</tr>';
i++;
}
htmlString += '</table>';
console.log(htmlString);
$("#wot").html(htmlString);
}
});
});
</script>
、私のPHPスクリプト:
<?php
$clanID = "500006494";
$clanApiPage = "https://api.worldoftanks.eu/wgn/clans/info/?application_id=demo&clan_id=$clanID";
$userApiPage = "https://api.worldoftanks.eu/wot/account/info/?application_id=demo&account_id=";
$clanStrongHoldPage = "https://developers.wargaming.net/reference/all/wot/stronghold/info?application_id=demo&clan_id=$clanID";
$getAndDecode = function($url) {
\t $jsonData = file_get_contents($url); \t \t \t
\t $dataArray = json_decode($jsonData, true);
\t return $dataArray;
};
$determineDays = function($date) {
\t $datediff = time() - $date;
\t return floor($datediff/(60*60*24));
};
$jsonData = $getAndDecode($clanApiPage) , ($clanStrongHoldPage);
$clanAccounts = array();
foreach($jsonData["data"][$clanID]["members"] as $memberArray) {
\t $accountID = $memberArray["account_id"];
\t $clanAccounts[$accountID]['id'] = $memberArray["account_id"];
\t $clanAccounts[$accountID]['role'] = $memberArray["role_i18n"];
\t $clanAccounts[$accountID]['name'] = $memberArray["account_name"];
\t $clanAccounts[$accountID]['days'] = $determineDays($memberArray["joined_at"]);
}
$accountIDs = implode(",", array_keys($clanAccounts));
$apiPage = $userApiPage . $accountIDs;
$userJsonData = $getAndDecode($apiPage);
foreach($userJsonData["data"] as $userID => $dataArray) {
\t $playerStatistic = $dataArray["statistics"]["all"];
\t $clanAccounts[$userID]['rating'] = $dataArray["global_rating"];
\t $clanAccounts[$userID]['battles'] = $playerStatistic["battles"];
\t $clanAccounts[$userID]['w_p_b'] = $playerStatistic["wins"]/$playerStatistic["battles"] * 100;//wins per battle
\t $clanAccounts[$userID]['xp_p_b'] = $playerStatistic["battle_avg_xp"]; //experience per battle
}
$w_p_b = array();
foreach ($clanAccounts as $userID => $row) {
\t $w_p_b[$userID] = $row['w_p_b'];
}
array_multisort($w_p_b, SORT_DESC, $clanAccounts);
die(json_encode($clanAccounts));
?>
ここに私のテーブルのサンプル:http://www.slovenian-army.tk/members.html
私はしたいと思いますイメージを近くに置くこのようなすべてのユーザー: sloa_clan
ユーザーのランクによって異なります。ユーザーがComanderの場合、彼は逃げるアイコンを取得します ユーザーがRecruitである場合、彼はRecruitアイコンを取得します。
ありがとうございました!
ようこそ:
とコードは今のように見えます。あなたの質問を編集してください、少なくとも詳細を指定してください。またはルールを読んで、良い質問をする方法。 http://stackoverflow.com/help – pedrouan