Nategood httpful接收数据

时间:2018-09-12 12:19:49

标签: php json httpful

嗨,我需要nategood httpful的帮助。我试图从我的一页到另一页获取数据。我有两个页面,其中1个叫做test,它是从数据库中获取数据。

<?php
//getting data from the database
require 'db.php';
$sql = R::findAll('charts');

$json = array();
foreach ($sql as $row) {
    array_push($json, $row);
}
echo json_encode($json);

上面的页面是测试,下面的代码用于api.php

<?php
require 'vendor/autoload.php';
$uri = 'http://localhost/codes/test.php';
//$uri = 'http://leadingdigital.co.zw/bfc/api/categories.php';
$response = \Httpful\Request::post($uri)->send();
foreach ($response as $data) {
    echo $data->body->id;
}

test.php页面应该给我们一个json数组,如

[{"id":"1","name":"Nigel","score":"50"},{"id":"2","name":"Gideo","score":"0"},{"id":"3","name":"Tasha","score":"80"},{"id":"4","name":"Tata","score":"76"},{"id":"5","name":"Nyasha","score":"23"}]

然后应使用api.php获取此数据

0 个答案:

没有答案