DubStepMad Posted March 3, 2018 Report Posted March 3, 2018 Hi, not sure if I am calling the api correctly and displaying the results right for the bans. Everything else works but not the bans for some reason. <?php $sqlget = 'SELECT * FROM players WHERE rank = "Veteran" ORDER BY joindate ASC'; $sqldataV = mysqli_query($dbcon, $sqlget); while($row = mysqli_fetch_array($sqldataV, MYSQLI_ASSOC)){ $json = file_get_contents('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=9B7EFDB256E798658715CE71D574D751&steamids='.$row['playerid'].''); $parsedV = json_decode($json); foreach($parsedV->response->players as $playerV){ } $online = $playerV->personastate; if ($online == '1'){ $bcolor = '4px solid #6eea15'; } else{ $bcolor = ''; } $json = file_get_contents('https://api.truckersmp.com/v2/player/'.$row['playerid'].''); $data = json_decode($json); $mpname = $data->response->name; $mpid = $data->response->id; $json2 = file_get_contents('https://api.truckersmp.com/v2/bans/'.$mpid.''); $data2 = json_decode($json2); $expiredate = $data2->response->expiration; $admin = $data2->response->adminName; echo'<li id="fleet" >'; echo "<center><img style='height:auto; width:auto; border:$bcolor;' class='img-circle' src='" . $playerV->avatarfull . "'></center>"; echo '<center><p style="margin-top: 65%;">'. $mpname . '<p></center>'; echo '<center><p style="margin-top: 65%;">'. $expiredate . '<p></center>'; echo'</li>'; } ?> Any help I will be greatful for. Into Code
GGF MD Posted March 3, 2018 Report Posted March 3, 2018 //moved to Developer Portal You will get help here. 1 ---------- TruckersMP Support Team Leader Support - Appeal - TruckersMP Rules - Feedback - Report Former TruckersMP Support Manager
Guest Posted March 3, 2018 Report Posted March 3, 2018 Hello @[TSRVTC] DubStepMad, Have I understood that correctly?: The essential content is displayed correctly, but not the bans? Regards,
DubStepMad Posted March 3, 2018 Author Report Posted March 3, 2018 (edited) 5 minutes ago, [AC] Group said: Hello @[TSRVTC] DubStepMad, Have I understood that correctly?: The essential content is displayed correctly, but not the bans? Regards, The MP name is displayed and everything else is correct but the ban information will not display at all. Now currently using my account as an example, I have 1 ban form 2016 and that doesnt display. Edited March 3, 2018 by [TSRVTC] DubStepMad Into Code
reaver_ Posted March 3, 2018 Report Posted March 3, 2018 After the line $data2 = json_decode($json2); you have to loop through the response array in $data2.
DubStepMad Posted March 3, 2018 Author Report Posted March 3, 2018 3 minutes ago, reaver_ said: After the line $data2 = json_decode($json2); you have to loop through the response array in $data2. Mind showing me an example since I still new to using APIs. Into Code
reaver_ Posted March 3, 2018 Report Posted March 3, 2018 5 minutes ago, [TSRVTC] DubStepMad said: Mind showing me an example since I still new to using APIs. Sure. This should work. $data2 = json_decode($json2); foreach($data2->response as $ban) { $expiredate = $ban->expiration; $admin = $ban->adminName; echo'<li id="fleet" >'; echo "<center><img style='height:auto; width:auto; border:$bcolor;' class='img-circle' src='" . $playerV->avatarfull . "'></center>"; echo '<center><p style="margin-top: 65%;">'. $mpname . '<p></center>'; echo '<center><p style="margin-top: 65%;">'. $expiredate . '<p></center>'; echo'</li>'; }
DubStepMad Posted March 3, 2018 Author Report Posted March 3, 2018 12 minutes ago, reaver_ said: Sure. This should work. $data2 = json_decode($json2); foreach($data2->response as $ban) { $expiredate = $ban->expiration; $admin = $ban->adminName; echo'<li id="fleet" >'; echo "<center><img style='height:auto; width:auto; border:$bcolor;' class='img-circle' src='" . $playerV->avatarfull . "'></center>"; echo '<center><p style="margin-top: 65%;">'. $mpname . '<p></center>'; echo '<center><p style="margin-top: 65%;">'. $expiredate . '<p></center>'; echo'</li>'; } Thank you, had to make a few changes but works now Into Code
DubStepMad Posted March 3, 2018 Author Report Posted March 3, 2018 (edited) This isn't working now foreach($data2->response as $ban) { $expiredate = $ban->expiration; $admin = $ban->adminName; $status = $ban->active; if ($status == 0) { echo '<center><p>' . $status . '<p></center>'; echo '<center><p>' . $expiredate . '<p></center>'; echo '<center><p>' . $admin . '<p></center>'; } } echo'</li>'; Status is only there to make sure I was checking the right thing. Edited March 3, 2018 by [TSRVTC] DubStepMad Into Code
reaver_ Posted March 4, 2018 Report Posted March 4, 2018 12 hours ago, [TSRVTC] DubStepMad said: This isn't working now foreach($data2->response as $ban) { $expiredate = $ban->expiration; $admin = $ban->adminName; $status = $ban->active; if ($status == 0) { echo '<center><p>' . $status . '<p></center>'; echo '<center><p>' . $expiredate . '<p></center>'; echo '<center><p>' . $admin . '<p></center>'; } } echo'</li>'; Status is only there to make sure I was checking the right thing. You have to compare $status with true if ($status == true) { // stuff }
DubStepMad Posted March 4, 2018 Author Report Posted March 4, 2018 58 minutes ago, reaver_ said: You have to compare $status with true if ($status == true) { // stuff } Didn't work for me but this did: if ($status == "0"){ //stuff } Into Code
Recommended Posts