K
K
Kolya Genzul2016-03-12 19:02:17
JSON
Kolya Genzul, 2016-03-12 19:02:17

How to display data from json?!??

help to display data from json! I've been trying to do it since morning!
U for server monitoring..
file online.json

{"16":{"version":"BungeeCord 1.8","online":72,"slots":400,"ping":330,"status":"online","percent":6},"0":{"status":"offline","percent":100,"online":"Off"},"1":{"status":"offline","percent":100,"online":"Off"},"2":{"status":"offline","percent":100,"online":"Off"},"3":{"version":"1.5.2","online":"3","slots":"100","ping":61,"status":"online","percent":34},"4":{"version":"1.5.2","online":"13","slots":"100","ping":99,"status":"online","percent":8},"5":{"version":"1.5.2","online":"40","slots":"100","ping":70,"status":"online","percent":3},"6":{"version":"1.6.4","online":"6","slots":"100","ping":1583,"status":"online","percent":17},"7":{"version":"1.6.4","online":"7","slots":"100","ping":90,"status":"online","percent":15},"8":{"version":"1.5.2","online":"43","slots":"125","ping":77,"status":"online","percent":3},"9":{"version":"1.5.2","online":"43","slots":"125","ping":72,"status":"online","percent":3},"10":{"version":"1.5.2","online":"43","slots":"125","ping":115,"status":"online","percent":3},"11":{"version":"1.6.4","online":"44","slots":"100","ping":1555,"status":"online","percent":3},"12":{"version":"1.6.4","online":"26","slots":"100","ping":1559,"status":"online","percent":4},"13":{"version":"kcauldron,cauldron,craftbukkit,mcpc,fml,forge 1.7.10","online":26,"slots":100,"ping":299,"status":"online","percent":4},"14":{"version":"kcauldron,cauldron,craftbukkit,mcpc,fml,forge 1.7.10","online":0,"slots":100,"ping":305,"status":"online"},"15":{"version":"kcauldron,cauldron,craftbukkit,mcpc,fml,forge 1.7.10","online":2,"slots":50,"ping":303,"status":"online","percent":25}}

index.php output
<meta charset="utf-8"/>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<link rel="stylesheet" href="css/main.css"/>
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="js/tipr.min.js"></script>
<?php
  error_reporting (1); // отключаем ошибки PHP
 include('config.php');

 $data = json_decode(file_get_contents(__DIR__.'/online.json'));
 $records = json_decode(file_get_contents(__DIR__.'/records.json'));

echo '<div class="col">';
foreach($col1 as $cat_id) {
    echo '<div class="server_cat_name">'.$categories[$cat_id].'</div>';
    foreach($servers as $id => $s){
        if($cat_id == $s[3]) {
            echo '
            <div class="monitoring">
                <div class="count_online">' .$data{$id}->online. '</div>
                <div class="descript">
                    <a href="'.$s[4].'" target="_blank" >'.$s[0].'</a>
                </div>
                <div class="line">
                    <div class="bar '.$data{$id}->status.'" style="width:'.$data{$id}->percent.'%;">
                        <div style="clear:both;"></div>
                    </div>
                </div>
                <div style="clear:both;"></div>
            </div>';
        }
    }
}
echo '</div>';

echo '<div class="col">';
foreach($col2 as $cat_id) {
    echo '<div class="server_cat_name">'.$categories[$cat_id].'</div>';
    foreach($servers as $id => $s){
        if($cat_id == $s[3]) {
            echo '
            <div class="monitoring">
                <div class="count_online" >' .$data{$id}->online. '</div>
                <div class="descript">
                    <a href="'.$s[4].'" target="_blank" >'.$s[0].'</a>
                </div>
                <div class="line">
                    <div class="bar '.$data{$id}->status.'" style="width:'.$data{$id}->percent.'%;">
                        <div style="clear:both;"></div>
                    </div>
                </div>
                <div style="clear:both;"></div>
            </div>';
        }
    }
}
echo '</div>';
echo '<div class="mon_footer">
<span class="tt" data-tip="Текущий онлайн"><i class="fa fa-circle-o-notch"></i> '.$records->totalOnline.'</span>
<span class="tt" data-tip="Рекорд за сегодня"><i class="fa fa-clock-o"></i> '.$records->dayOnlineCount.'</span>
<span class="tt" data-tip="Рекорд"><i class="fa fa-arrow-up"></i> '.$records->maxOnlineCount.'</span>
</div>'
?>

<script>
    $(document).ready(function() {
        $('.tt').tipr({
            'style': 'dark',
            'mode': 'top'
        });
    });
</script>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kolya Genzul, 2016-03-12
@kela_1997

"Number": - This is the id that is specified in the config!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question