Jump to content

Why content in for loop not displaying on browser?


tatarao

Recommended Posts

Dear friends,

 

 

        I am new to PHP coding. I wrote a php script to display linux system hardware information in a browser. The script includes execution of linux commands and the result those command appended to one variable. To find usb information i wrote for loop within the script. When I am executing the script from linux terminal, it displays everything accurately. But the same script does not display the for loop result in case of browser. I attached my script with this post.

 

Please find a solution and let me know what I have to do.

 

 

 

Thanking you in advance.

 

regards,

 

Tata Rao,

pihealth.php

PHP developer,

 

Mobodexter

You've made this a lot harder on yourself. It looks like you're trying to format and print json by hand.

 

I would recommend doing something along the lines of:

$data_array = array(
    'current_time' => '',
    'uptime' => '',
    'load_averages' => '',
    'temperature' => '',
    'memory' => array(
        'ram' => array(
            'total' => '',
            'used' => '',
            'free' => '',
            'mem_percentage' => '',
            'units' => 'Gigabytes'
        ),
        'sd_card' => array(
            'total' => '',
            'used' => '',
            'free' => '',
            'mem_percentage' => '',
            'units' => 'Gigabytes'
        ),
    )
);

echo json_encode($data_array);

To set the RAM memory total

$data_array['memory']['ram']['total'] = $where_ever_ram_total_comes_from;

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.