Hey guys,

I'm very new to this so please forgive me.
I have a theme that I am trying to use to display some stats from my minecraft server (Yes I am one of those people :) )

The dashboard theme has a load of charts that are in a <scipt> tag and I am basically wondering how I use some values that I am getting through a json query.

This is what I have and what I thought would work, but obvisly it is not otherwise I would not be here.

                        <div class="col-md-4 col-sm-4 mb"> <div class="grey-panel pn donut-chart"> <div class="grey-header"> <h5>Online Players</h5> </div> <canvas id="serverstatus01" height="120" width="120"></canvas> <script>
                                    var doughnutData = [
                                            {
                                                value: <?php echo $info['playerCount']; ?>,
                                                color:"#FF6B6B"
                                            },
                                            {
                                                value : <?php echo $info['maxPlayers']; ?>,,
                                                color : "#fdfdfd"
                                            }
                                        ];
                                        var myDoughnut = new Chart(document.getElementById("serverstatus01").getContext("2d")).Doughnut(doughnutData);
                                </script> <div class="row"> <div class="col-sm-6 col-xs-6 goleft"> <p>Usage<br/>Increase:</p> </div> <div class="col-sm-6 col-xs-6"> <h2>21%</h2> </div> </div> </div><! --/grey-panel --> </div><!-- /col-md-4-->

I have this at the top which includes my .php files on the core file.

<?php

include('core/init.inc.php')

$info = fetch_server_info($config['server']['ip'], $config['server']['port'];
?> 

The “json query” you refer to is the doughnutData at line 2 ? Do you want to use it server side (in PHP) or client side (in JavaScript) ?. How do you want to use this array of objects , what do you want to do with it? If you just want to use the variable doughnutData , client side just add a line after 11 alert(doughnutData[0]["color"]); and you used it.

Sorry, I want to display this on a website and the query is minequery. This pings the server to see if its online, how many people are online and few other stats. It returns an aray of which playerCount and maxPlayers are apart of.
I myself added <?php echo $info['playerCount']; ?>, it had just a plan vaule there before.
The original code was this

                      <!-- SERVER STATUS PANELS -->
                        <div class="col-md-4 col-sm-4 mb">
                            <div class="grey-panel pn donut-chart">
                                <div class="grey-header">
                                    <h5>SERVER LOAD</h5>
                                </div>
                                <canvas id="serverstatus01" height="120" width="120"></canvas>
                                <script>
                                    var doughnutData = [
                                            {
                                                value: 70,
                                                color:"#FF6B6B"
                                            },
                                            {
                                                value : 30,
                                                color : "#fdfdfd"
                                            }
                                        ];
                                        var myDoughnut = new Chart(document.getElementById("serverstatus01").getContext("2d")).Doughnut(doughnutData);
                                </script>
                                <div class="row">
                                    <div class="col-sm-6 col-xs-6 goleft">
                                        <p>Usage<br/>Increase:</p>
                                    </div>
                                     <div class="col-sm-6 col-xs-6">
                                        <h2>21%</h2>
                                     </div>
                                </div>
                            </div><! --/grey-panel -->
                        </div><!-- /col-md-4-->

First step is to check what $info actaully contains.
Below
$info = fetch_server_info($config['server']['ip'], $config['server']['port'];
add
var_dump($info);die();
Run the page and the contents of $info will get output to the screen.
Ou tof curiosity what does get put onto the page now?

at the moment its a complete dashboard (Dashio Theme).
I nievely purchased the theme thinking it was a complete theme with backend code, but it it really is is just a graphical makeup of what the site could look like.

At the moment if I just make a simple html page and add it in, it just displays html almost as if it is broken.

<?php

include('core/init.inc.php')

$info = fetch_server_info($config['server']['ip'], $config['server']['port'];
var_dump($info);die();
?>
<!DOCTYPE html PUBLIC "-//WCW//DTD XHTML 1.1 Strict//EN" "http://www.org/TR/xhtml1-strict.dtd">
<html xmlns="http://w3.org/1999/xhtml">
    <head>
        <meta html-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title><?php echo $config['server']['ip']; ?></title>
    </head>
    <body>
        <div>

        </div>
    </body>
</html>

config is this:

<?php

$config['server']['ip'] = 'ftb.empy.in';
$config['server']['port'] = '255566';

>

This is where Im getting it from: http://betterphp.co.uk/playlist.html?pid=PL87FDBD109078B9BF

Sorry, but to check something, when you say "At the moment if I just make a simple html page" you mean you make a page with a .php extension and run it on a server right?

Yeah.
Well im opening it in Chrome, its still all located on my PC.
Probably a noob thing todo and probably wont load that way?

PHP is server side code, it needs to be ran on a server (Apache running on your PC for instance). A collection of PHP files sitting on your PC won't run correctly. A browser will serve up the HTML ok but any PHP won't do anything.

What an idiot.

Thanks hericles!

I really have no experience running php.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.