limiting foreach() results

Hello all,

i have a page that pulls api data from a remote server and to do this i am using a foreach() meathod what i need to know is how can i tell it to only pull the data that is >= 1?

so i guess the easiest way to explain it is, i want to set the vars for all available achievements but only display the ones with a value of 1 or more with a full color image and the ones with a value of 0 with a faded version of the same image… (the below vars are not all of them…)

the function:
[php]public function process_wowsachievs($wws_id)
{
$this->template->assign_vars(array(
‘S_WWS_HAS_PROFILE’ => true,
‘WWS_ID’ => $wws_id,
));

	$ch = curl_init();
	// Achievements
	$apiuri = 'https://api.worldofwarships.com/wows/account/achievements/?application_id=a3a64dfac090e84c33c25d816e4d2ccd&account_id='.$wws_id.'&language=en';
	curl_setopt($ch, CURLOPT_URL, $apiuri);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	$wowsachievs = json_decode(curl_exec($ch), true);
	curl_close($ch);

		foreach ($wowsachievs['data'] AS $key => $value) {
			$this->template->assign_block_vars(wowsachievs, array(
			'WWSA_DOUBLE_KILL'			=> $value['battle']['DOUBLE_KILL'],
			'WWSA_LIQUIDATOR'			=> $value['battle']['LIQUIDATOR'],
			'WWSA_WARRIOR'				=> $value['battle']['WARRIOR'],
			'WWSA_DETONATED'			=> $value['battle']['DETONATED'],
			'WWSA_WITHERING'			        => $value['battle']['WITHERING'],
			'WWSA_ARSONIST'				=> $value['battle']['ARSONIST'],
			'WWSA_CBT_PARTICIPANT'		=> $value['battle']['CBT_PARTICIPANT'],
			'WWSA_RAWDATA'				=> print_r ($value, true),				
		));
	}
}[/php]

the display code:
[php]

Achievements:

Double Killx{wowsachievs.WWSA_DOUBLE_KILL} Double Strike Liquidatorx{wowsachievs.WWSA_LIQUIDATOR} Liquidator Kraken Unleashed!x{wowsachievs.WWSA_WARRIOR} Kraken Unleashed! Detonationx{wowsachievs.WWSA_DETONATED} Detonation Withererx{wowsachievs.WWSA_WITHERING} Witherer CBT Veteranx{wowsachievs.WWSA_CBT_PARTICIPANT} CBT Veteran Arsonistx{wowsachievs.WWSA_ARSONIST} Arsonist

[/php]

the actual data being pulled from the api call:

[code]Array
(
[battle] => Array
(
[RETRIBUTION] => 81
[FIGHTER] => 1
[BD2016_RUN_FOREST] => 1
[NY17_TO_THE_BOTTOM] => 1
[MILLIONAIR] => 1
[CAMPAIGN_NY17B_COMPLETED] => 1
[MERCENARY] => 1
[MESSENGER] => 1
[UNSINKABLE] => 10
[SCIENCE_OF_WINNING_ARSONIST] => 1
[NY17_AIMING] => 1
[SCIENCE_OF_WINNING_TACTICIAN] => 1
[MESSENGER_L] => 1
[BATTLE_HERO] => 1
[BD2016_WRONG_SOW] => 1
[DOUBLE_KILL] => 11
[CAMPAIGN1_COMPLETED] => 1
[BD2016_MANNERS] => 1
[NY17_DRESS_THE_TREE] => 1
[MAIN_CALIBER] => 22
[INSTANT_KILL] => 224
[NY17_500_LEAGUES] => 1
[JUNIOR_PLANNER] => 1
[NY17_WIN_ALL] => 1
[ENGINEER] => 1
[SCIENCE_OF_WINNING_HARD_EDGED] => 1
[ATBA_CALIBER] => 5
[BD2016_SNATCH] => 1
[MERCENARY_L] => 1
[BD2016_PARTY_ANIMAL] => 1
[HALLOWEEN_2016] => 1
[SCIENCE_OF_WINNING_TO_THE_BOTTOM] => 1
[VETERAN] => 1
[NO_DAY_WITHOUT_ADVENTURE] => 1
[NEVER_ENOUGH_MONEY] => 1
[NY17_BREAK_THE_BANK] => 1
[DREADNOUGHT] => 18
[CAPITAL] => 1
[BD2016_FESTIV_SOUP] => 1
[SCIENCE_OF_WINNING_BOMBARDIER] => 1
[CLEAR_SKY] => 63
[ARSONIST] => 8
[WARRIOR] => 3
[WORKAHOLIC] => 1
[FIRST_BLOOD] => 181
[DETONATED] => 40
[SUPPORT] => 11
[NY17_SAFECRACKER] => 1
[WITHERING] => 1
[BD2016_FIRESHOW] => 1
[NO_DAY_WITHOUT_ADVENTURE_L] => 1
[NY17_WIN_AT_LEAST_ONE] => 1
[FIREPROOF] => 9
[BD2016_PARTY_CHECK_IN] => 1
[CAMPAIGN_NY17B_COMPLETED_EXCELLENT] => 1
[CBT_PARTICIPANT] => 1
[AMAUTEUR] => 1
[LIQUIDATOR] => 4
[SCIENCE_OF_WINNING_LUCKY] => 1
)

[progress] => Array
    (
        [MERCENARY_L] => 0
        [WORKAHOLIC] => 0
        [FIGHTER] => 0
        [NO_DAY_WITHOUT_ADVENTURE] => 0
        [BATTLE_HERO] => 0
        [NEVER_ENOUGH_MONEY] => 0
        [NO_DAY_WITHOUT_ADVENTURE_L] => 0
        [MERCENARY] => 0
        [JUNIOR_PLANNER] => 0
        [CAPITAL] => 0
        [MESSENGER] => 0
        [SCIENCE_OF_WINNING_BOMBARDIER] => 0
        [MESSENGER_L] => 0
        [AMAUTEUR] => 0
        [VETERAN] => 0
        [MILLIONAIR] => 0
        [ENGINEER] => 0
    )

)[/code]

notice there are some that just have an “x” next to them. I want the image to show if the value is 0 just not the x as the image will be a different version (faded out)

like this:

sorry for dbl post time ran out to modify,

if it helps the path to the >=1 images is images/normal/WARRIOR.png
and the path to the ==0 images is images/inactive/WARRIOR.png

i also believe that all image names are identical to the key name of the array as well … (not sure if this helps)

Just need to check the values of what is returned. Then to a ternary statement on whether you should display the full color or faded image.

ok how would i do that do you have an example?

ok so i have gotten this to work as i want but now i need to change the label into a nicer readable format …

as you can see here:

now i have another function that pulls all possible achievements from the remote server and places their system name and nice name into an array (NOTE not all of these achievements will be on everyone’s profile as some may not have been earned yet)

[php]function process_allachievs()
{
$ch = curl_init();
// Pull All Acheivements and build array of System Name => Readable Name
$apiuri = ‘https://api.worldofwarships.com/wows/encyclopedia/achievements/?application_id=a3a64dfac090e84c33c25d816e4d2ccd&language=en’;
curl_setopt($ch, CURLOPT_URL, $apiuri);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$wowsachievements = json_decode(curl_exec($ch), true);
curl_close($ch);

		foreach ($wowsachievements['data']['battle'] AS $key => $value) {
			if ($value['type'] == "honorable"){
				$arry[] =  array($key => $value['name']);
			}
		}
}[/php]

which outputs this:

[code]Array
(
[0] => Array
(
[FIGHTER] => Warrior
)

[1] => Array
    (
        [CAMPAIGN_SB_COMPLETED] => "Honorable Service"
    )

[2] => Array
    (
        [CAMPAIGN_NY17B_COMPLETED] => "The Hunt for Graf Spee"
    )

[3] => Array
    (
        [NO_DAY_WITHOUT_ADVENTURE_L] => Smooth Supply
    )

[4] => Array
    (
        [SEA_LEGEND] => Bane of the Oceans
    )

[5] => Array
    (
        [MESSENGER] => In the Thick of It
    )

[6] => Array
    (
        [UNSINKABLE] => Unsinkable
    )

[7] => Array
    (
        [SCIENCE_OF_WINNING_ARSONIST] => Naval Warfare. Arson
    )

[8] => Array
    (
        [CAMPAIGN_SB_COMPLETED_EXCELLENT] => "Honorable Service" with Honors
    )

[9] => Array
    (
        [ATBA_CALIBER] => Close Quarters Expert
    )

[10] => Array
    (
        [SCIENCE_OF_WINNING_TACTICIAN] => Naval Warfare. Tactics
    )

[11] => Array
    (
        [MESSENGER_L] => Junior Supply Officer
    )

[12] => Array
    (
        [BATTLE_HERO] => Battle Hero
    )

[13] => Array
    (
        [CAMPAIGN1_COMPLETED] => "Science of Victory"
    )

[14] => Array
    (
        [WORKAHOLIC_L] => Senior Supply Officer
    )

[15] => Array
    (
        [HEADBUTT] => Die-Hard
    )

[16] => Array
    (
        [INSTANT_KILL] => Devastating Strike
    )

[17] => Array
    (
        [CAMPAIGN_NY17B_COMPLETED_EXCELLENT] => "The Hunt for Graf Spee" with Honors
    )

[18] => Array
    (
        [SCIENCE_OF_WINNING_HARD_EDGED] => Naval Warfare. Ramming
    )

[19] => Array
    (
        [MERCENARY_L] => Supply Officer
    )

[20] => Array
    (
        [SCIENCE_OF_WINNING_TO_THE_BOTTOM] => Naval Warfare. Flooding
    )

[21] => Array
    (
        [VETERAN] => Veteran
    )

[22] => Array
    (
        [NO_DAY_WITHOUT_ADVENTURE] => A Day Without Adventure Is a Wasted One
    )

[23] => Array
    (
        [MERCENARY] => Workhorse
    )

[24] => Array
    (
        [NO_PRICE_FOR_HEROISM] => Legend of the Seas
    )

[25] => Array
    (
        [CAMPAIGN1_COMPLETED_EXCELLENT] => "Science of Victory" with Honors
    )

[26] => Array
    (
        [SCIENCE_OF_WINNING_BOMBARDIER] => Naval Warfare. Weaponry Basics
    )

[27] => Array
    (
        [CLEAR_SKY] => Clear Sky
    )

[28] => Array
    (
        [CAMPAIGN_NY17E_COMPLETED] => "Santa's Christmas Convoys"
    )

[29] => Array
    (
        [DOUBLE_KILL] => Double Strike
    )

[30] => Array
    (
        [FIREPROOF] => Fireproof
    )

[31] => Array
    (
        [RETRIBUTION] => It's Just a Flesh Wound!
    )

[32] => Array
    (
        [WORKAHOLIC] => Ready for Anything
    )

[33] => Array
    (
        [FIRST_BLOOD] => First Blood
    )

[34] => Array
    (
        [DETONATED] => Detonation
    )

[35] => Array
    (
        [LIQUIDATOR] => Liquidator
    )

[36] => Array
    (
        [CAMPAIGN_NY17E_COMPLETED_EXCELLENT] => "Santa's Christmas Convoys" with Honors
    )

[37] => Array
    (
        [ARSONIST] => Arsonist
    )

[38] => Array
    (
        [AMAUTEUR] => Amateur
    )

[39] => Array
    (
        [SCIENCE_OF_WINNING_LUCKY] => Naval Warfare. Lucky Shot
    )

)[/code]

how can i combine that array information into the listings to show the nice name instead of the system name??

[php] function process_wowsachievs($wws_id)
{
$ch = curl_init();
// Achievements
$apiuri = ‘https://api.worldofwarships.com/wows/account/achievements/?application_id=a3a64dfac090e84c33c25d816e4d2ccd&account_id=’.$wws_id.’&language=en’;
curl_setopt($ch, CURLOPT_URL, $apiuri);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$wowsachievs = json_decode(curl_exec($ch), true);
curl_close($ch);
foreach ($wowsachievs[‘data’][$wws_id][‘battle’] AS $key => $value) {
if ($value >= ‘1’) {
echo ‘'.$key.'x’.$value.’’.$key.’’;
}
}
}[/php]

:slight_smile: ok so after some trial and error i have found “A” way to do what i wanted … all be it may not be the correct way. It does take forever to load the page so i really need some help figuring out the right and fast loading way to do this …

here is what i did to get these results …

i created a new function that pulls the system name and the friendly name from the remote servers API
[php]function convert_wotanames($sysname)
{
$ch = curl_init();
// Player Stats
$apiuri = ‘https://api.worldoftanks.com/wot/encyclopedia/achievements/?application_id=a3a64dfac090e84c33c25d816e4d2ccd&language=en&fields=name_i18n%2C+name’;
curl_setopt($ch, CURLOPT_URL, $apiuri);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$wotanames = json_decode(curl_exec($ch), true);
curl_close($ch);
$data = $wotanames[‘data’][$sysname];
if (in_array($sysname, $data, true)){
echo $data[‘name_i18n’];
}
}[/php]

then i altered my original function to display the achievements to the following
[php]function display_achievements($sysname){
$ch = curl_init();
$apiuri = ‘https://api.worldoftanks.com/wot/account/achievements/?application_id=a3a64dfac090e84c33c25d816e4d2ccd&language=en&account_id=’.$wws_id;
curl_setopt($ch, CURLOPT_URL, $apiuri);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$wotachievs = json_decode(curl_exec($ch), true);
curl_close($ch);
foreach ($wotachievs[‘data’][$wws_id][‘achievements’] AS $key => $value) {
$nname = convert_wotanames($key);
if ($value >= ‘2’) {
echo ‘'.$key.'x’.$value.’’.$nname.’’;
}else{
echo ‘'.$key.'’.$nname.’’;
}
}
foreach ($wotachievs[‘data’][$wws_id][‘frags’] AS $key2 => $value2) {
$nname2 = convert_wotanames($key2);
if ($value2 >= ‘2’) {
echo ‘'.$key2.'x’.$value2.’’.$nname2.’’;
}else{
echo ‘'.$key2.'’.$nname2.’’;
}
}
foreach ($wotachievs[‘data’][$wws_id][‘max_series’] AS $key3 => $value3) {
$nname3 = convert_wotanames($key3);
if ($value3 >= ‘2’) {
echo ‘'.$key3.'x’.$value3.’’.$nname3.’’;
}else{
echo ‘'.$key3.'’.$nname3.’’;
}
}
}[/php]
by calling the new function with

$nname = convert_wotanames($key);

it now compares the players achievements $key name with the servers $key name and uses the friendly name for the caption, but as i said it takes forever for the page to generate, how can i speed this up? Currently it is taking 45.5659 seconds to generate the page.

You currently have several foreach loops that could probably be combined.

ive never been good at combining multiple bits of code like that … :frowning: if you can show me how to combine 1 or 2 of them i can take it from there even if you just use some random code as an example of combining 2 foreach() statements would be alot of help.

Send me what is returned from the API call.

http://aacgaming.com/Archangel/test.php

here is all the data that all the api calls are pulling

here is the entire test.php
[php]
figure {
display: inline-block;
width: 10%;
margin-right: 1px;
font-size: 10px ;
font-weight: bold;
text-align: center;
text-overflow: ellipsis;
margin: 0.5em;
padding: 0.5em;
}
img.scaled {
width: 50%;
}

<?php error_reporting(-1); ini_set('display_errors', 1); $wws_id = '1000064633'; function convert_wotanames($sysname) { $ch = curl_init(); // Player Stats $apiuri = 'https://api.worldoftanks.com/wot/encyclopedia/achievements/?application_id=a3a64dfac090e84c33c25d816e4d2ccd&language=en&fields=name_i18n%2C+name'; curl_setopt($ch, CURLOPT_URL, $apiuri); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $wotanames = json_decode(curl_exec($ch), true); curl_close($ch); $data = $wotanames['data'][$sysname]; echo '

Raw output:WoT Encylopedia

'; echo '
';
    print_r($wotanames['data']);
    echo '
'; } function process_wowsstats($wws_id) { $ch = curl_init(); // Player Stats $apiuri = 'https://api.worldofwarships.com/wows/account/info/?application_id=a3a64dfac090e84c33c25d816e4d2ccd&account_id=' . $wws_id . '&language=en'; curl_setopt($ch, CURLOPT_URL, $apiuri); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $wowsstats = json_decode(curl_exec($ch), true); curl_close($ch); foreach ($wowsstats['data'] AS $key => $value) { echo '
'; echo '

Raw output: Player Stats

'; echo '
';
        print_r($value);
        echo '
'; } } function process_allachievs() { $ch = curl_init(); // Pull All Acheivements and build array of System Name => Readable Name $apiuri = 'https://api.worldofwarships.com/wows/encyclopedia/achievements/?application_id=a3a64dfac090e84c33c25d816e4d2ccd&language=en'; curl_setopt($ch, CURLOPT_URL, $apiuri); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $wowsachievements = json_decode(curl_exec($ch), true); curl_close($ch); foreach ($wowsachievements['data']['battle'] AS $key => $value) { $arry[] = array( $key => $value['name'] ); } echo '
'; echo '

Raw output:WoWs Encyclopedia

'; echo '
';
    print_r($arry);
    echo '
'; } function process_wowsachievs($wws_id) { $ch = curl_init(); // Achievements $apiuri = 'https://api.worldofwarships.com/wows/account/achievements/?application_id=a3a64dfac090e84c33c25d816e4d2ccd&account_id=' . $wws_id . '&language=en'; curl_setopt($ch, CURLOPT_URL, $apiuri); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $wowsachievs = json_decode(curl_exec($ch), true); curl_close($ch); echo '
'; echo '

Raw output: WoWs Achievments

'; foreach ($wowsachievs['data'][$wws_id]['battle'] AS $key => $value) { if ($value >= '1') { echo '' . $key . 'x' . $value . '' . $key . ''; } } echo '
';
    print_r($value);
    echo '
'; } function process_wowsranked($wws_id) { $ch = curl_init(); // Ranked Stats $apiuri = 'https://api.worldofwarships.com/wows/seasons/accountinfo/?application_id=a3a64dfac090e84c33c25d816e4d2ccd&account_id=' . $wws_id . '&language=en'; curl_setopt($ch, CURLOPT_URL, $apiuri); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $wowsranked = json_decode(curl_exec($ch), true); curl_close($ch); foreach ($wowsranked['data'] AS $key => $value) { echo '
'; echo '

Raw output:WoWs Season Information

'; echo '
';
        print_r($value);
        echo '
'; } } echo convert_wotanames('medalEkins'); echo process_wowsstats($wws_id); echo process_wowsachievs($wws_id); echo process_wowsranked($wws_id); ?>[/php]

Sorry for dbl post i noticed that was an old version of the test.php … here is the updated one…

EDIT: Forgot to comment out the return in the Encyclopedia functions so that the output will be displayed.

[php]
figure {
display: inline-block;
width: 10%;
margin-right: 1px;
font-size: 14px !important;
font-weight: bold;
text-align: center;
text-overflow: ellipsis;
margin: 0.5em;
padding: 0.5em;
}
img.scaled {
width: 50%;
}

<?php error_reporting(-1); $time = microtime(); $time = explode(' ', $time); $time = $time[1] + $time[0]; $start = $time; $wws_id = '1000064633'; //for testing only will normally be $wws_id = $_GET['pID']; $wotsysname = 'medalEkins'; //for testing only will normally not be here at all $wowssysname = 'UNSINKABLE'; //for testing only will normally not be here at all /* WoT Achievements Nice Names */ function convert_wotanames($wotsysname) { $ch = curl_init(); $apiuri = 'https://api.worldoftanks.com/wot/encyclopedia/achievements/?application_id=a3a64dfac090e84c33c25d816e4d2ccd&language=en&fields=name_i18n%2C+name'; curl_setopt($ch, CURLOPT_URL, $apiuri); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $wotanames = json_decode(curl_exec($ch), true); curl_close($ch); $data = $wotanames['data'][$wotsysname]; //return $data['name']; echo '

Raw output:WoT Achievements Encylopedia

'; echo '
';
    print_r($wotanames['data']);
    echo '
'; } /* WoWs Achievements Nice Names */ function convert_wowsanames($wowssysname) { $ch = curl_init(); $apiuri = 'https://api.worldofwarships.com/wows/encyclopedia/achievements/?application_id=a3a64dfac090e84c33c25d816e4d2ccd&language=en&fields=battle.name'; curl_setopt($ch, CURLOPT_URL, $apiuri); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $wowsanames = json_decode(curl_exec($ch), true); curl_close($ch); $data = $wowsanames['data']['battle'][$wowssysname]; //return $data['name']; echo '

Raw output:WoWs Achievements Encylopedia

'; echo '
';
    print_r($wowsanames['data']['battle']);
    echo '
'; } /* WoWs Player Achievements */ function process_wowsachievs($wws_id) { $ch = curl_init(); $apiuri = 'https://api.worldofwarships.com/wows/account/achievements/?application_id=a3a64dfac090e84c33c25d816e4d2ccd&account_id='.$wws_id.'&language=en'; curl_setopt($ch, CURLOPT_URL, $apiuri); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $wowsachievs = json_decode(curl_exec($ch), true); curl_close($ch); foreach ($wowsachievs['data'][$wws_id]['battle'] AS $key => $value) { if ($value >= '2') { echo ''.$key.'x'.$value.''.$key.''; }else{ echo ''.$key.''.$key.''; } } echo '

Raw output:WoWs Player Achievements:

'; echo '
';
    print_r($wowsachievs['data'][$wws_id]['battle']);
    echo '
'; } /* WoT Player Achievements */ function process_wotachievs($wws_id) { $ch = curl_init(); $apiuri = 'https://api.worldoftanks.com/wot/account/achievements/?application_id=a3a64dfac090e84c33c25d816e4d2ccd&language=en&account_id='.$wws_id; curl_setopt($ch, CURLOPT_URL, $apiuri); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $wotachievs = json_decode(curl_exec($ch), true); curl_close($ch); foreach ($wotachievs['data'][$wws_id]['achievements'] AS $key => $value) { switch($key){ case "medalCarius": $ext = $value.'.png'; break; case "medalEkins": $ext = $value.'.png'; break; case "readyForBattleLT": $ext = $value.'.png'; break; case "markOfMastery": $ext = $value.'.png'; break; case "medalLavrinenko": $ext = $value.'.png'; break; case "strategicOperations": $ext = $value.'.png'; break; case "medalKnispel": $ext = $value.'.png'; break; case "kampfer": $ext = $value.'.png'; break; case "medalKay": $ext = $value.'.png'; break; case "medalAbrams": $ext = $value.'.png'; break; case "medalRotmistrov": $ext = $value.'.png'; break; case "conqueror": $ext = $value.'.png'; break; case "readyForBattleMT": $ext = $value.'.png'; break; case "fireAndSword": $ext = $value.'.png'; break; case "forTacticalOperations": $ext = $value.'.png'; break; case "readyForBattleHT": $ext = $value.'.png'; break; case "medalPoppel": $ext = $value.'.png'; break; case "guardsman": $ext = $value.'.png'; break; case "readyForBattleSPG": $ext = $value.'.png'; break; case "readyForBattleATSPG": $ext = $value.'.png'; break; case "medalLeClerc": $ext = $value.'.png'; break; case "makerOfHistory": $ext = $value.'.png'; break; case "battleTested": $ext = $value.'.png'; break; case "soldierOfFortune": $ext = $value.'.png'; break; default: $ext = '.png'; break; } if ($value >= '2') { echo ''.$key.'x'.$value.''.$key.''; }else{ echo ''.$key.''.$key.''; } } echo '

Raw output:WoT Player Achievements:

'; echo '
';
    print_r($wotachievs['data'][$wws_id]['achievements']);
    echo '
'; } /* WoWs Player Stats */ function process_wowsstats($wws_id) { $ch = curl_init(); $apiuri = 'https://api.worldofwarships.com/wows/account/info/?application_id=a3a64dfac090e84c33c25d816e4d2ccd&account_id=' . $wws_id . '&language=en'; curl_setopt($ch, CURLOPT_URL, $apiuri); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $wowsstats = json_decode(curl_exec($ch), true); curl_close($ch); foreach ($wowsstats['data'] AS $key => $value) { echo '
'; echo '

Raw output: WoWs Player Stats

'; echo '
';
        print_r($value);
        echo '
'; } } /* WoT Player Stats */ function process_wotstats($wws_id) { $ch = curl_init(); $apiuri = 'https://api.worldoftanks.com/wot/account/info/?application_id=a3a64dfac090e84c33c25d816e4d2ccd&account_id='.$wws_id.'&language=en'; curl_setopt($ch, CURLOPT_URL, $apiuri); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $wotstats = json_decode(curl_exec($ch), true); curl_close($ch); foreach ($wotstats['data'] AS $key => $value) { echo '
'; echo '

Raw output: WoT Player Stats

'; echo '
';
        print_r($value);
        echo '
'; } } /* WoWs Ranked Season Info */ function process_wowsranked($wws_id) { $ch = curl_init(); $apiuri = 'https://api.worldofwarships.com/wows/seasons/accountinfo/?application_id=a3a64dfac090e84c33c25d816e4d2ccd&account_id=' . $wws_id . '&language=en'; curl_setopt($ch, CURLOPT_URL, $apiuri); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $wowsranked = json_decode(curl_exec($ch), true); curl_close($ch); foreach ($wowsranked['data'] AS $key => $value) { echo '
'; echo '

Raw output:WoWs Season Information

'; echo '
';
        print_r($value);
        echo '
'; } } /* WoT Ranked Season Info */ function process_wotranked($wws_id) { $ch = curl_init(); $apiuri = 'https://api.worldofwarships.com/wows/seasons/accountinfo/?application_id=a3a64dfac090e84c33c25d816e4d2ccd&account_id='.$wws_id.'&language=en'; curl_setopt($ch, CURLOPT_URL, $apiuri); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $wotranked = json_decode(curl_exec($ch), true); curl_close($ch); foreach ($wotranked['data'] AS $key => $value) { echo '
'; echo '

Raw output:WoT Season Information

'; echo '
';
        print_r($value);
        echo '
'; } } process_wowsstats($wws_id); process_wowsachievs($wws_id); convert_wowsanames($wowssysname); process_wowsranked($wws_id); process_wotstats($wws_id); process_wotachievs($wws_id); convert_wotanames($wotsysname); process_wotranked($wws_id); $time = microtime(); $time = explode(' ', $time); $time = $time[1] + $time[0]; $finish = $time; $total_time = round(($finish - $start), 4); echo 'Page generated in '.$total_time.' seconds.'; ?>[/php]

I have been swamped today, but here is one shortcut.

[php]$achievements = $wotachievs[‘data’][$wws_id][‘achievements’][$key];
$frags = $wotachievs[‘data’][$wws_id][‘frags’][$key];
$series = $wotachievs[‘data’][$wws_id][‘max_series’][$key];[/php]

Now that the keys are specifically identified, you should be able to have a decision structure that pulls the correct image.

The raw json return is more helpful than a dump of the array.

ok you want the pre json_decode? or post? (ive changed the code to print_r ($var = json_decode(curl_exec($ch), true):wink: on all areas.

what part is this in lieu of ?

you should be able to copy out my last post and open there are no other files that it depends on .

i’ve got the page displaying just the raw json data now in a textarea so its easier to grab

[member=72272]astonecipher[/member] was that output better for you?

I have been so vusy I haven’t been able to look at any outside code and run it

no worries man im in no rush, 8) get with me when you can. take it easy and dont let it get to you.

i have this working but i had to build a massive switch case which i don’t like because if they add more achievements i will have to go back and add to the switch but here is the expected output in case you wanted to see what i was trying to achieve.

the 2 links below are members of this site, notice that their Main Game Played is selecting which stats to show.

GhostRider - WoWs
Rankori - WoT

this is just informative, not trying to pressure you at all.

A switch statement isn’t a bad thing at all when used properly. That would might be a route to go honestly.

Sponsor our Newsletter | Privacy Policy | Terms of Service