MyBB Community Forums

Full Version: Make php land in a table/div
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Alright. So here is my custom mybb page. The thing is, I've put some php in it, but I have no idea how to display it in a table or div. It lands under the footer at the moment.
Appreciate any help!
Thanks in advance!
 

// Replace XXXXXX by your server id on Trackyserver.com
$server_id = "1683849";

// Execute curl and get server informations
$url="https://api.trackyserver.com/widget/index.php?id=".$server_id;
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL,$url);
$result=json_decode(curl_exec($ch), true);
curl_close($ch);

if ($result){
// Example to print playerscount
echo $result['playerscount'];
echo $result['map'];
// Example to loop players list
foreach ($result['playerslist'] as $player){
echo $player['name'];
}
// Use print_r($result); to print all informations array
} else {
echo "server not found";
}
You need to output a template instead of directly echoing data - see here: https://community.mybb.com/thread-116225.html
(2022-03-01, 02:57 PM)Matt Wrote: [ -> ]You need to output a template instead of directly echoing data - see here: https://community.mybb.com/thread-116225.html

<?php

define('IN_MYBB', 1); require "./global.php";

add_breadcrumb("Servrar", "servrar.php");

eval("\$html = \"".$templates->get("servrar")."\";");

output_page($html);




// Replace XXXXXX by your server id on Trackyserver.com
$server_id = "1683849";

// Execute curl and get server informations
$url="https://api.trackyserver.com/widget/index.php?id=".$server_id;
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL,$url);
$result=json_decode(curl_exec($ch), true);
curl_close($ch);

if ($result){
  // Example to print playerscount
  echo $result['playerscount'];
  echo $result['map'];  
  // Example to loop players list  
  foreach ($result['playerslist'] as $player){  
    echo $player['name'];  
  }  
  // Use print_r($result); to print all informations array  
} else {
  echo "server not found";
}

?>


(2022-03-01, 02:57 PM)Matt Wrote: [ -> ]You need to output a template instead of directly echoing data - see here: https://community.mybb.com/thread-116225.html

I already did Toungue
The output_page is supposed to be the last line, logically you can’t output the page and then define the values afterwards. You need to define variables that you then use in the template.
(2022-03-01, 09:53 PM)Matt Wrote: [ -> ]The output_page is supposed to be the last line, logically you can’t output the page and then define the values afterwards. You need to define variables that you then use in the template.

And how do I do that? Im very bad at php.