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

Link to comment
Share on other sites

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;
  • Like 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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