• Announcements

    • LIGHTOFGOD

      Active Recruitments   02/24/18

      Game Moderator Recruitment - 11th of August to 30th of September 2018   Find out more information, here:      
    • Prime

      Current Hot topic: ETS and ATS 1.32   08/12/18

      What do you think the impanct of 1.32 will be on TruckersMP and how the mod will be played,...   Discuss it all with us in this Hot topic:  

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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
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.

 

Share this post


Link to post
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>';
}

 

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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

}

 

Share this post


Link to post
Share on other sites
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
}

 

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now