我尝试使用此代码从文件 json.php 加载数据,它工作正常
$data = [
[id=>1, name=>"Billy Bob", progress=>"12", gender=>"male", height=>1, col=>"red", dob=>"", driver=>1],
[id=>2, name=>"Mary May", progress=>"1", gender=>"female", height=>2, col=>"blue", dob=>"14/05/1982", driver=>true],
[id=>3, name=>"Christine Lobowski", progress=>"42", height=>0, col=>"green", dob=>"22/05/1982", driver=>"true"],
[id=>4, name=>"Brendon Philips", progress=>"125", gender=>"male", height=>1, col=>"orange", dob=>"01/08/1980"],
[id=>5, name=>"Margret Marmajuke", progress=>"16", gender=>"female", height=>5, col=>"yellow", dob=>"31/01/1999"],
];
//返回JSON格式数据
echo(json_encode(["last_page"=>30, "data"=>$data]));
但是我的数据存储在 postgres 的数据库表中。在同一个文件中,我用这个替换了代码,但不起作用
$sql = "SELECT * from cross_reference";
$result = pg_exec($sql);
$data = array();
while($row = pg_fetch_assoc($result)) {
$data[] = $row;
}
echo (json_encode(["last_page"=>30, "data"=>$data]));
你能帮我吗!?谢谢