Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 对html表格式的多个Json响应_Php_Mysql_Json_Html Table_Response - Fatal编程技术网

Php 对html表格式的多个Json响应

Php 对html表格式的多个Json响应,php,mysql,json,html-table,response,Php,Mysql,Json,Html Table,Response,我想从不同的数据库服务器获取数据,我需要显示在一个集中的服务器上。因此,我在不同的位置编写了一个SELECT查询,并尝试在一个集中的服务器中获取。 我收到一个JSON数组响应。 但是我尝试用HTML表格格式显示它,但是我无法得到正确的结果 以下是我的集中式服务器PHP代码: <?php $arr = array ( 'http://example.com/pristatus/send-curl.php',

我想从不同的数据库服务器获取数据,我需要显示在一个集中的服务器上。因此,我在不同的位置编写了一个SELECT查询,并尝试在一个集中的服务器中获取。 我收到一个JSON数组响应。

但是我尝试用HTML表格格式显示它,但是我无法得到正确的结果

以下是我的集中式服务器PHP代码:

 <?php 
    $arr = array (
                    'http://example.com/pristatus/send-curl.php', 
                    'http://example2.com/pristatus/send-curl.php'
                );

                for ($i =0; $i<count($arr); $i++)
                {

                    $ch = curl_init(); 
                    curl_setopt($ch, CURLOPT_URL, $arr[$i]); 
                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
                $output = curl_exec($ch); 

            if($output!="error"){
                    $data = json_decode($output);
                }
                echo "<pre>";
                print_r($data);
                curl_close($ch); 
                }
    ?>

请建议我如何以表格格式显示Json响应。

您需要使用foreach循环,然后通过类似的方式获取值

echo '<table>';
foreach($data as $key) {
    echo '<tr>';
    echo '<td>'.$key->{'id'}.'<td>';
    echo '<td>'.$key->{'status'}.'</td>';
    echo '<td>'.$key->{'batch'}.'</td>';
    echo '<td>'.$key->{'location'}.'</td>';
    echo '<td>'.$key->{'createdDT'}.'</td>';
    echo '</tr>';
}
echo '</table>';
例如:

echo';
Array
(
    [0] => stdClass Object
        (
            [id] => 9
            [status] => OK
            [batch] => 119677
            [location] => Hyderabad
            [createdDT] => 2015-06-19 20:40:05
        )

)
Array
(
    [0] => stdClass Object
        (
            [id] => 1
            [status] => OK
            [batch] => 56339
            [location] => Mumbai
            [createdDT] => 2015-06-19 20:40:05
        )

    [1] => stdClass Object
        (
            [id] => 2
            [status] => OK
            [batch] => 56339
            [location] => Mumbai
            [createdDT] => 2015-06-19 20:40:05
        )    
)
foreach($数据作为$key){ 回声';
Array
(
    [0] => stdClass Object
        (
            [id] => 9
            [status] => OK
            [batch] => 119677
            [location] => Hyderabad
            [createdDT] => 2015-06-19 20:40:05
        )

)
Array
(
    [0] => stdClass Object
        (
            [id] => 1
            [status] => OK
            [batch] => 56339
            [location] => Mumbai
            [createdDT] => 2015-06-19 20:40:05
        )

    [1] => stdClass Object
        (
            [id] => 2
            [status] => OK
            [batch] => 56339
            [location] => Mumbai
            [createdDT] => 2015-06-19 20:40:05
        )    
)
回显'.$key->{'id'}';
Array
(
    [0] => stdClass Object
        (
            [id] => 9
            [status] => OK
            [batch] => 119677
            [location] => Hyderabad
            [createdDT] => 2015-06-19 20:40:05
        )

)
Array
(
    [0] => stdClass Object
        (
            [id] => 1
            [status] => OK
            [batch] => 56339
            [location] => Mumbai
            [createdDT] => 2015-06-19 20:40:05
        )

    [1] => stdClass Object
        (
            [id] => 2
            [status] => OK
            [batch] => 56339
            [location] => Mumbai
            [createdDT] => 2015-06-19 20:40:05
        )    
)
回显'.$key->{'status'}';
Array
(
    [0] => stdClass Object
        (
            [id] => 9
            [status] => OK
            [batch] => 119677
            [location] => Hyderabad
            [createdDT] => 2015-06-19 20:40:05
        )

)
Array
(
    [0] => stdClass Object
        (
            [id] => 1
            [status] => OK
            [batch] => 56339
            [location] => Mumbai
            [createdDT] => 2015-06-19 20:40:05
        )

    [1] => stdClass Object
        (
            [id] => 2
            [status] => OK
            [batch] => 56339
            [location] => Mumbai
            [createdDT] => 2015-06-19 20:40:05
        )    
)
回显'.$key->{'batch'}';
Array
(
    [0] => stdClass Object
        (
            [id] => 9
            [status] => OK
            [batch] => 119677
            [location] => Hyderabad
            [createdDT] => 2015-06-19 20:40:05
        )

)
Array
(
    [0] => stdClass Object
        (
            [id] => 1
            [status] => OK
            [batch] => 56339
            [location] => Mumbai
            [createdDT] => 2015-06-19 20:40:05
        )

    [1] => stdClass Object
        (
            [id] => 2
            [status] => OK
            [batch] => 56339
            [location] => Mumbai
            [createdDT] => 2015-06-19 20:40:05
        )    
)
回显'.$key->{'location'}';
Array
(
    [0] => stdClass Object
        (
            [id] => 9
            [status] => OK
            [batch] => 119677
            [location] => Hyderabad
            [createdDT] => 2015-06-19 20:40:05
        )

)
Array
(
    [0] => stdClass Object
        (
            [id] => 1
            [status] => OK
            [batch] => 56339
            [location] => Mumbai
            [createdDT] => 2015-06-19 20:40:05
        )

    [1] => stdClass Object
        (
            [id] => 2
            [status] => OK
            [batch] => 56339
            [location] => Mumbai
            [createdDT] => 2015-06-19 20:40:05
        )    
)
回显'.$key->{'createdDT'}';
Array
(
    [0] => stdClass Object
        (
            [id] => 9
            [status] => OK
            [batch] => 119677
            [location] => Hyderabad
            [createdDT] => 2015-06-19 20:40:05
        )

)
Array
(
    [0] => stdClass Object
        (
            [id] => 1
            [status] => OK
            [batch] => 56339
            [location] => Mumbai
            [createdDT] => 2015-06-19 20:40:05
        )

    [1] => stdClass Object
        (
            [id] => 2
            [status] => OK
            [batch] => 56339
            [location] => Mumbai
            [createdDT] => 2015-06-19 20:40:05
        )    
)
回声';
Array
(
    [0] => stdClass Object
        (
            [id] => 9
            [status] => OK
            [batch] => 119677
            [location] => Hyderabad
            [createdDT] => 2015-06-19 20:40:05
        )

)
Array
(
    [0] => stdClass Object
        (
            [id] => 1
            [status] => OK
            [batch] => 56339
            [location] => Mumbai
            [createdDT] => 2015-06-19 20:40:05
        )

    [1] => stdClass Object
        (
            [id] => 2
            [status] => OK
            [batch] => 56339
            [location] => Mumbai
            [createdDT] => 2015-06-19 20:40:05
        )    
)
} 回声';
Array
(
    [0] => stdClass Object
        (
            [id] => 9
            [status] => OK
            [batch] => 119677
            [location] => Hyderabad
            [createdDT] => 2015-06-19 20:40:05
        )

)
Array
(
    [0] => stdClass Object
        (
            [id] => 1
            [status] => OK
            [batch] => 56339
            [location] => Mumbai
            [createdDT] => 2015-06-19 20:40:05
        )

    [1] => stdClass Object
        (
            [id] => 2
            [status] => OK
            [batch] => 56339
            [location] => Mumbai
            [createdDT] => 2015-06-19 20:40:05
        )    
)

Use。如果是JSON,那么就使用
JSON\u decode()
这真是太棒了!