Jump to content

API Ban call


Recommended Posts

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.

mV7R3Lk.png 

Into Code

Link to comment
Share on other sites

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 by [TSRVTC] DubStepMad

mV7R3Lk.png 

Into Code

Link to comment
Share on other sites

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>';
}

 

Link to comment
Share on other sites

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 :D

mV7R3Lk.png 

Into Code

Link to comment
Share on other sites

This isn't working now :wacko:

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 by [TSRVTC] DubStepMad

mV7R3Lk.png 

Into Code

Link to comment
Share on other sites

12 hours ago, [TSRVTC] DubStepMad said:

This isn't working now :wacko:


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

}

 

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.