Author Topic: limiting foreach() results  (Read 650 times)

jay7981

  • Regular Member
  • **
  • Posts: 96
  • Karma: 2
  • I don't know what I don't know and neither do you.
    • View Profile
    • Angeldyne
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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
  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($chCURLOPT_URL$apiuri);
 
	
	
curl_setopt($chCURLOPT_RETURNTRANSFER1);
 
	
	
$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 ($valuetrue),
	
	
	
	

 
	
	
	
));
 
	
	
}
 
	
}




the display code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  <!-- IF S_WWS_HAS_PROFILE && .wowsstats && .wowsachievs && .wowsranked -->
  <
div class="panel">
  
	
	
<
div class="inner">
  
	
	
<!-- 
BEGIN wowsachievs -->
  
	
	
<
h2>Achievements:</h2>
  
	
	
<
p>
  
	
	
<
figure>
  
	
	
<
img src="http://api.worldofwarships.com/static/1.11.0/wows/encyclopedia/achievements/normal/DOUBLE_KILL.png" alt="Double Kill">x{wowsachievs.WWSA_DOUBLE_KILL
  
	
	
<
figcaption>Double Strike</figcaption>
 
	
	
</
figure>
 
	
	
<
figure>
 
	
	
<
img src="http://api.worldofwarships.com/static/1.11.0/wows/encyclopedia/achievements/normal/LIQUIDATOR.png" alt="Liquidator">x{wowsachievs.WWSA_LIQUIDATOR}
 
	
	
<
figcaption>Liquidator</figcaption>
 
	
	
</
figure>
 
	
	
<
figure>
 
	
	
<
img src="http://api.worldofwarships.com/static/1.11.0/wows/encyclopedia/achievements/normal/WARRIOR.png" alt="Kraken Unleashed!">x{wowsachievs.WWSA_WARRIOR}
 
	
	
<
figcaption>Kraken Unleashed!</figcaption>
 
	
	
</
figure>
 
	
	
<
figure>
	
	

 
	
	
<
img src="http://api.worldofwarships.com/static/1.11.0/wows/encyclopedia/achievements/normal/DETONATED.png" alt="Detonation">x{wowsachievs.WWSA_DETONATED}
 
	
	
<
figcaption>Detonation</figcaption>
 
	
	
</
figure>
 
	
	
<
figure>
 
	
	
<
img src="http://api.worldofwarships.com/static/1.11.0/wows/encyclopedia/achievements/normal/WITHERING.png" alt="Witherer">x{wowsachievs.WWSA_WITHERING}
 
	
	
<
figcaption>Witherer</figcaption>
 
	
	
</
figure>
 
	
	
<
figure>
 
	
	
<
img src="http://api.worldofwarships.com/static/1.11.0/wows/encyclopedia/achievements/normal/CBT_PARTICIPANT.png" alt="CBT Veteran">x{wowsachievs.WWSA_CBT_PARTICIPANT}
 
	
	
<
figcaption>CBT Veteran</figcaption>
 
	
	
</
figure>
 
	
	
<
figure>
 
	
	
<
img src="http://api.worldofwarships.com/static/1.11.0/wows/encyclopedia/achievements/normal/ARSONIST.png" alt="Arsonist">x{wowsachievs.WWSA_ARSONIST}
 
	
	
<
figcaption>Arsonist</figcaption>
 
	
	
</
figure></p>
 
	
	
<!-- 
END wowsachievs -->
 
	
</
div>
 </
div>
 <!-- ENDIF -->



the actual data being pulled from the api call:
Code: [Select]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
  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
         )
 
 )

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:
« Last Edit: February 13, 2017, 03:13:59 am by jay7981 »
Please read before posting - Posting Guidelines - Please read before posting
<-- Press my Give Karma button if I was helpful.

PHP Help Forum

limiting foreach() results
« on: February 13, 2017, 02:39:23 am »



PHP Help Forum

Re: limiting foreach() results
« Reply #1 on: February 13, 2017, 03:23:42 am »



PHP Help Forum

Re: limiting foreach() results
« Reply #2 on: February 13, 2017, 04:25:51 pm »



PHP Help Forum

Re: limiting foreach() results
« Reply #3 on: February 13, 2017, 04:36:27 pm »


jay7981

  • Regular Member
  • **
  • Posts: 96
  • Karma: 2
  • I don't know what I don't know and neither do you.
    • View Profile
    • Angeldyne
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)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  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($chCURLOPT_URL$apiuri);
  
	
	
curl_setopt($chCURLOPT_RETURNTRANSFER1);
  
	
	
$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']);
 
	
	
	
	
}
 
	
	
	
}
 
	
}



which outputs this:
Code: [Select]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
   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
         )
 
 )


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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  
	
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($chCURLOPT_URL$apiuri);
  
	
	
curl_setopt($chCURLOPT_RETURNTRANSFER1);
  
	
	
$wowsachievs json_decode(curl_exec($ch), true);
  
	
	
curl_close($ch);
 
	
	
	
foreach (
$wowsachievs['data'][$wws_id]['battle'] AS $key => $value) {
 
	
	
	
	
if (
$value >= '1') {
 
	
	
	
	
echo 
'<figure><img src="http://api.worldofwarships.com/static/1.11.0/wows/encyclopedia/achievements/normal/'.$key.'.png" alt="'.$key.'">x'.$value.'<figcaption>'.$key.'</figcaption></figure>';
 
	
	
	
	
}
 
	
	
	
}
 
	
}


 
« Last Edit: February 15, 2017, 12:08:04 pm by jay7981 »
Please read before posting - Posting Guidelines - Please read before posting
<-- Press my Give Karma button if I was helpful.

PHP Help Forum

Re: limiting foreach() results
« Reply #4 on: February 15, 2017, 12:06:18 pm »


jay7981

  • Regular Member
  • **
  • Posts: 96
  • Karma: 2
  • I don't know what I don't know and neither do you.
    • View Profile
    • Angeldyne
 :) 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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  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($chCURLOPT_URL$apiuri);
  
	
	
curl_setopt($chCURLOPT_RETURNTRANSFER1);
  
	
	
$wotanames json_decode(curl_exec($ch), true);
  
	
	
curl_close($ch);
 
	
	
	
$data $wotanames['data'][$sysname];
 
	
	
	
	
if (
in_array($sysname$datatrue)){
 
	
	
	
	
	
echo 
$data['name_i18n'];
 
	
	
	
	
}
 
	
}



then i altered my original function to display the achievements to the following
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
  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($chCURLOPT_URL$apiuri);
  
	
	
curl_setopt($chCURLOPT_RETURNTRANSFER1);
  
	
	
$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 
'<figure><img class=scaled src="http://api.worldoftanks.com/static/2.52.0/wot/encyclopedia/achievement/'.$key.$ext.'" alt="'.$key.'">x'.$value.'<figcaption>'.$nname.'</figcaption></figure>';
 
	
	
	
	
	
	
}else{
 
	
	
	
	
	
	
	
echo 
'<figure><img class=scaled src="http://api.worldoftanks.com/static/2.52.0/wot/encyclopedia/achievement/'.$key.$ext.'" alt="'.$key.'"><figcaption>'.$nname.'</figcaption></figure>';
 
	
	
	
	
	
	
}
 
	
	
	
	
	
}
 
	
	
	
	
	
foreach (
$wotachievs['data'][$wws_id]['frags'] AS $key2 => $value2) {
 
	
	
	
	
	
	
$nname2 convert_wotanames($key2);
 
	
	
	
	
	
	
if (
$value2 >= '2') {
 
	
	
	
	
	
	
	
echo 
'<figure><img class=scaled src="http://api.worldoftanks.com/static/2.52.0/wot/encyclopedia/achievement/'.$key2.$ext.'" alt="'.$key2.'">x'.$value2.'<figcaption>'.$nname2.'</figcaption></figure>';
 
	
	
	
	
	
	
}else{
 
	
	
	
	
	
	
	
echo 
'<figure><img class=scaled src="http://api.worldoftanks.com/static/2.52.0/wot/encyclopedia/achievement/'.$key2.$ext.'" alt="'.$key2.'"><figcaption>'.$nname2.'</figcaption></figure>';
 
	
	
	
	
	
	
}
 
	
	
	
	
	
}
 
	
	
	
	
	
foreach (
$wotachievs['data'][$wws_id]['max_series'] AS $key3 => $value3) {
 
	
	
	
	
	
	
$nname3 convert_wotanames($key3);
 
	
	
	
	
	
	
if (
$value3 >= '2') {
 
	
	
	
	
	
	
	
echo 
'<figure><img class=scaled src="http://api.worldoftanks.com/static/2.52.0/wot/encyclopedia/achievement/'.$key3.$ext.'" alt="'.$key3.'">x'.$value3.'<figcaption>'.$nname3.'</figcaption></figure>';
 
	
	
	
	
	
	
}else{
 
	
	
	
	
	
	
	
echo 
'<figure><img class=scaled src="http://api.worldoftanks.com/static/2.52.0/wot/encyclopedia/achievement/'.$key3.$ext.'" alt="'.$key3.'"><figcaption>'.$nname3.'</figcaption></figure>';
 
	
	
	
	
	
	
}
 
	
	
	
	
	
}
 
	
}


by calling the new function with
Code: [Select]
1
 $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.
« Last Edit: February 15, 2017, 05:47:07 pm by jay7981 »
Please read before posting - Posting Guidelines - Please read before posting
<-- Press my Give Karma button if I was helpful.

PHP Help Forum

Re: limiting foreach() results
« Reply #5 on: February 15, 2017, 05:38:08 pm »



PHP Help Forum

Re: limiting foreach() results
« Reply #6 on: February 16, 2017, 09:30:24 am »



PHP Help Forum

Re: limiting foreach() results
« Reply #7 on: February 16, 2017, 09:36:48 am »



PHP Help Forum

Re: limiting foreach() results
« Reply #8 on: February 16, 2017, 10:07:18 am »


jay7981

  • Regular Member
  • **
  • Posts: 96
  • Karma: 2
  • I don't know what I don't know and neither do you.
    • View Profile
    • Angeldyne
http://aacgaming.com/Archangel/test.php

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

here is the entire test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
   <style>
   
figure 
   
	
displayinline-block;
   
	
width10%;
   
	
margin-right1px;
   
	
font-size10px ;
   
	
font-weightbold;
   
	
text-aligncenter;
   
	
text-overflowellipsis;
  
	
margin0.5em;
  
	
padding0.5em;
  }
  
img.scaled {
    
width50%;
  }
  </
style>
  <?
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($chCURLOPT_URL$apiuri);
      
curl_setopt($chCURLOPT_RETURNTRANSFER1);
      
$wotanames json_decode(curl_exec($ch), true);
      
curl_close($ch);
      
$data $wotanames['data'][$sysname];
      echo 
'<p><h1>Raw output:WoT Encylopedia</h1></p>';
      echo 
'<pre>';
      
print_r($wotanames['data']);
      echo 
'</pre>';
  }
  
  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($chCURLOPT_URL$apiuri);
      
curl_setopt($chCURLOPT_RETURNTRANSFER1);
      
$wowsstats json_decode(curl_exec($ch), true);
      
curl_close($ch);
      
      foreach (
$wowsstats['data'] AS $key => $value) {
          echo 
'<hr>';
          echo 
'<p><h1>Raw output: Player Stats</h1></p>';
          echo 
'<pre>';
          
print_r($value);
          echo 
'</pre>';
      }
  }
  
  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($chCURLOPT_URL$apiuri);
      
curl_setopt($chCURLOPT_RETURNTRANSFER1);
      
$wowsachievements json_decode(curl_exec($ch), true);
      
curl_close($ch);
      
      foreach (
$wowsachievements['data']['battle'] AS $key => $value) {
          
$arry[] = array(
              
$key => $value['name']
          );
      }
      echo 
'<hr>';
      echo 
'<p><h1>Raw output:WoWs Encyclopedia</h1></p>';
      echo 
'<pre>';
      
print_r($arry);
      echo 
'</pre>';
  }
  
  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($chCURLOPT_URL$apiuri);
      
curl_setopt($chCURLOPT_RETURNTRANSFER1);
      
$wowsachievs json_decode(curl_exec($ch), true);
      
curl_close($ch);
      echo 
'<hr>';
      echo 
'<p><h1>Raw output: WoWs Achievments</h1></p>';
      foreach (
$wowsachievs['data'][$wws_id]['battle'] AS $key => $value) {
          if (
$value >= '1') {
              echo 
'<figure><img class=scaled src="http://api.worldofwarships.com/static/1.11.0/wows/encyclopedia/achievements/normal/' $key '.png" alt="' $key '"><small>x' $value '</small><figcaption>' $key '</figcaption></figure>';
          }
      }
      echo 
'<pre>';
      
print_r($value);
      echo 
'</pre>';
  }
  
  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($chCURLOPT_URL$apiuri);
     
curl_setopt($chCURLOPT_RETURNTRANSFER1);
     
$wowsranked json_decode(curl_exec($ch), true);
     
curl_close($ch);
     
     foreach (
$wowsranked['data'] AS $key => $value) {
         echo 
'<hr>';
         echo 
'<p><h1>Raw output:WoWs Season Information</h1></p>';
         echo 
'<pre>';
         
print_r($value);
         echo 
'</pre>';
     }
 }
 echo 
convert_wotanames('medalEkins');
 echo 
process_wowsstats($wws_id);
 echo 
process_wowsachievs($wws_id);
 echo 
process_wowsranked($wws_id);
 
 
?>



« Last Edit: February 16, 2017, 10:29:39 am by jay7981 »
Please read before posting - Posting Guidelines - Please read before posting
<-- Press my Give Karma button if I was helpful.

jay7981

  • Regular Member
  • **
  • Posts: 96
  • Karma: 2
  • I don't know what I don't know and neither do you.
    • View Profile
    • Angeldyne
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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
   <style>
       
figure {
           
displayinline-block;
           
width10%;
           
margin-right1px;
           
font-size14px !important;
           
font-weightbold;
           
text-aligncenter;
           
text-overflowellipsis;
          
margin0.5em;
          
padding0.5em;
      }
      
img.scaled {
          
width50%;
      }
  </
style>
  <?
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($chCURLOPT_URL$apiuri);
      
curl_setopt($chCURLOPT_RETURNTRANSFER1);
      
$wotanames json_decode(curl_exec($ch), true);
      
curl_close($ch);
      
$data $wotanames['data'][$wotsysname];
      
//return $data['name'];
  
	
echo 
'<p><h1>Raw output:WoT Achievements Encylopedia</h1></p>';
      echo 
'<pre>';
      
print_r($wotanames['data']);
      echo 
'</pre>';
  }
  
  
/* 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($chCURLOPT_URL$apiuri);
      
curl_setopt($chCURLOPT_RETURNTRANSFER1);
      
$wowsanames json_decode(curl_exec($ch), true);
      
curl_close($ch);
      
$data $wowsanames['data']['battle'][$wowssysname];
      
//return $data['name'];
  
	
echo 
'<p><h1>Raw output:WoWs Achievements Encylopedia</h1></p>';
      echo 
'<pre>';
      
print_r($wowsanames['data']['battle']);
      echo 
'</pre>';
  }
  
  
/* 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($chCURLOPT_URL$apiuri);
      
curl_setopt($chCURLOPT_RETURNTRANSFER1);
      
$wowsachievs json_decode(curl_exec($ch), true);
      
curl_close($ch);
      foreach (
$wowsachievs['data'][$wws_id]['battle'] AS $key => $value) {
  
	
	
	
	
if (
$value >= '2') {
  
	
	
	
	
echo 
'<figure><img class=scaled src="http://api.worldofwarships.com/static/1.11.0/wows/encyclopedia/achievements/normal/'.$key.'.png" alt="'.$key.'">x'.$value.'<figcaption>'.$key.'</figcaption></figure>';
  
	
	
	
	
}else{
  
	
	
	
	
echo 
'<figure><img class=scaled src="http://api.worldofwarships.com/static/1.11.0/wows/encyclopedia/achievements/normal/'.$key.'.png" alt="'.$key.'"><figcaption>'.$key.'</figcaption></figure>';
  
	
	
	
	
}
  
	
	
	
}
  
	
echo 
'<p><h1>Raw output:WoWs Player Achievements:</h1></p>';
      echo 
'<pre>';
      
print_r($wowsachievs['data'][$wws_id]['battle']);
      echo 
'</pre>';
  }
  
  
/* 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($chCURLOPT_URL$apiuri);
      
curl_setopt($chCURLOPT_RETURNTRANSFER1);
      
$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 
'<figure><img class=scaled src="http://api.worldoftanks.com/static/2.52.0/wot/encyclopedia/achievement/'.$key.$ext.'" alt="'.$key.'">x'.$value.'<figcaption>'.$key.'</figcaption></figure>';
 
	
	
	
	
}else{
 
	
	
	
	
echo 
'<figure><img class=scaled src="http://api.worldoftanks.com/static/2.52.0/wot/encyclopedia/achievement/'.$key.$ext.'" alt="'.$key.'"><figcaption>'.$key.'</figcaption></figure>';
 
	
	
	
	
}
 
	
	
	
}
 
	
echo 
'<p><h1>Raw output:WoT Player Achievements:</h1></p>';
     echo 
'<pre>';
     
print_r($wotachievs['data'][$wws_id]['achievements']);
     echo 
'</pre>';
 }
 
 
/* 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($chCURLOPT_URL$apiuri);
     
curl_setopt($chCURLOPT_RETURNTRANSFER1);
     
$wowsstats json_decode(curl_exec($ch), true);
     
curl_close($ch);
     
     foreach (
$wowsstats['data'] AS $key => $value) {
         echo 
'<hr>';
         echo 
'<p><h1>Raw output: WoWs Player Stats</h1></p>';
         echo 
'<pre>';
         
print_r($value);
         echo 
'</pre>';
     }
 }
 
 
/* 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($chCURLOPT_URL$apiuri);
     
curl_setopt($chCURLOPT_RETURNTRANSFER1);
     
$wotstats json_decode(curl_exec($ch), true);
     
curl_close($ch);
     
     foreach (
$wotstats['data'] AS $key => $value) {
         echo 
'<hr>';
         echo 
'<p><h1>Raw output: WoT Player Stats</h1></p>';
         echo 
'<pre>';
         
print_r($value);
         echo 
'</pre>';
     }
 }
 
 
/* 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($chCURLOPT_URL$apiuri);
     
curl_setopt($chCURLOPT_RETURNTRANSFER1);
     
$wowsranked json_decode(curl_exec($ch), true);
     
curl_close($ch);
     
     foreach (
$wowsranked['data'] AS $key => $value) {
         echo 
'<hr>';
         echo 
'<p><h1>Raw output:WoWs Season Information</h1></p>';
         echo 
'<pre>';
         
print_r($value);
         echo 
'</pre>';
     }
 }
 
 
/* 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($chCURLOPT_URL$apiuri);
     
curl_setopt($chCURLOPT_RETURNTRANSFER1);
     
$wotranked json_decode(curl_exec($ch), true);
     
curl_close($ch);
     
     foreach (
$wotranked['data'] AS $key => $value) {
         echo 
'<hr>';
         echo 
'<p><h1>Raw output:WoT Season Information</h1></p>';
         echo 
'<pre>';
         
print_r($value);
         echo 
'</pre>';
     }
 }
 
 
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.';
 
?>

« Last Edit: February 16, 2017, 11:22:39 am by jay7981 »
Please read before posting - Posting Guidelines - Please read before posting
<-- Press my Give Karma button if I was helpful.

astonecipher

  • Software Engineer
  • Professional PHP Helper
  • Senior Member
  • *
  • Posts: 2425
  • Karma: 95
    • View Profile
I have been swamped today, but here is one shortcut.

1
2
3
 $achievements $wotachievs['data'][$wws_id]['achievements'][$key];
 
$frags $wotachievs['data'][$wws_id]['frags'][$key];
 
$series $wotachievs['data'][$wws_id]['max_series'][$key];



Now that the keys are specifically identified, you should be able to have a decision structure that pulls the correct image.
Questions? Go here first.
http://www.phptherightway.com/


jay7981

  • Regular Member
  • **
  • Posts: 96
  • Karma: 2
  • I don't know what I don't know and neither do you.
    • View Profile
    • Angeldyne
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);) on all areas.

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

1
2
3
 $achievements $wotachievs['data'][$wws_id]['achievements'][$key];
 
$frags $wotachievs['data'][$wws_id]['frags'][$key];
 
$series $wotachievs['data'][$wws_id]['max_series'][$key];



Now that the keys are specifically identified, you should be able to have a decision structure that pulls the correct image.
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 .
Please read before posting - Posting Guidelines - Please read before posting
<-- Press my Give Karma button if I was helpful.