Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.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 来自URL的JqGrid数据_Php_Json_Jqgrid - Fatal编程技术网

Php 来自URL的JqGrid数据

Php 来自URL的JqGrid数据,php,json,jqgrid,Php,Json,Jqgrid,我正在从API解码JSON: $api = "http://xyzdomain.com/api"; $json = file_get_contents($api); $array = json_decode($json,true); print_r($array); 下面是API对象和数组的示例结果 Array ( [status] => ok [count] => 1 [meta] => Array ( [count] =>

我正在从API解码JSON:

$api = "http://xyzdomain.com/api";
$json = file_get_contents($api);
$array = json_decode($json,true);
print_r($array); 
下面是API对象和数组的示例结果

Array
(
[status] => ok
[count] => 1
[meta] => Array
        (
            [count] => 1
        )

[data] => Array
        (
                [accountid] => Array
                (
                    [0] => Array
                        (
                            [all] => Array
                                (
                                    [fans] => 16
                                    [user post] => 333
                                    [user Details] => xyz
                                )
                            [scorelist] => 1
                            [name] => John Doe 1
                            [timespent] => 5887
                            [nation] => usa
                        )
                    [1] => Array
                        (
                            [all] => Array
                                (
                                    [fans] => 123
                                    [user post] => 903
                                    [user Details] => mno
                                )
                            [scorelist] => 6
                            [name] => John Doe 2
                            [timespent] => 1269
                            [nation] => usa
                        )
                    [2] => Array
                        (
                            [all] => Array
                                (
                                    [fans] => 16
                                    [user post] => 303
                                    [user Details] => abc
                                )
                            [scorelist] => 1
                            [name] => John Doe 3
                            [timespent] => 9292
                            [nation] => ussr
                        )
                    [3] => Array
                        (
                            [all] => Array
                                (
                                    [fans] => 16
                                    [user post] => 333
                                    [user Details] => jqr
                                )
                            [scorelist] => 1
                            [name] => John Doe 4
                            [timespent] => 75600
                            [nation] => usa
                        )
                )
        )
)
我只使用了三个以上的样品,但它可能会上升到500或更多

我这里基本上有两个问题:

  • 我想使用jqgrid或datatables或任何其他看起来不错的方式制作一个表
  • 在上面的例子中,我如何计算国家(比如美国)所花费的时间

  • 我不确定您打算如何将数据放入datatables中,您可以将foreach循环中每个
    $account
    数组中的数据回显到
    元素中。

    完美我得到了这个。它就像一个符咒。如何在多个api数组中搜索。like account_id在两个json解码数组中都是相同的。如何从两个数组中搜索和合并数据到第三个数组。这取决于您试图搜索和合并的内容。我不建议尝试合并API提供给您的阵列,我认为最好检查每个阵列并根据您需要的数据构建一个自定义阵列。我对您的问题进行了修剪和整理,以更快地触及问题的核心。任何人都可以了解代码的方向,如何在JqGrid中填充上述示例数据。
    $timespent_usa = 0;
    foreach($array['data']['accountid'] as $account) {
    
        if ($account['nation'] == 'usa') {
            $timespent_usa += $account['timespent'];
        }
    }
    echo $timespent_usa;