【发布时间】:2016-06-08 09:21:23
【问题描述】:
我有这个 json 数据
{
"next_offset": -1,
"records": [
{
"id": "87dad127-a60e-15a3-148e-56c7675f11df",
"name": "1A Unit",
"suite": "1A",
"sf": 1200,
"unit_floor": 1,
},
{
"id": "f386a7ad-d6ea-6eb1-9b8f-56cd6104c445",
"name": "3B Unit",
"suite": "3B",
"sf": 450,
"unit_floor": 3,
},
{
"id": "b352dc84-8c76-6c27-daa4-56cd61e71aa2",
"name": "3A Unit",
"suite": "3A",
"sf": 450,
"unit_floor": 3,
},
{
"id": "8ec4325a-1271-560e-888b-56cd6120f5de",
"name": "2B Unit",
"suite": "2B",
"sf": 450,
"unit_floor": 2,
},
{
"id": "5a15fd5e-246a-be4b-fd5d-56cd619e9ee1",
"name": "1B Unit",
"suite": "1B",
"sf": 450,
"unit_floor": 1,
},
{
"id": "61a55092-5683-1088-2d6c-56c99c5d4873",
"name": "2A Unit",
"suite": "2A",
"sf": 3000,
"unit_floor": 2,
}
]
}
我想根据楼层数在表格中显示此数据。就像 3 楼单位 3A、3B 及其一排的总面积(以平方英尺为单位)、2 楼单位 2A、2B 及其一排的面积总和以及一楼的单位 1A、1B 及其一排的面积总和。请帮帮我。
我试过了,但它没有给出预期的结果
$unit_response = call($url, $oauth2_token_response->access_token, 'GET');
$unit_json = json_decode(json_encode($unit_response),true);
<table class="stak-plan">
<?php foreach ($unit_json['records'] as $unit_data) { ?>
<tr>
<td>Floor: 3</td>
<td>
Suit : <?php echo $unit_data['name'] ?><br>
SF : <?php echo $unit_data['sf'] ?>
</td>
<td>Suite: 3B<br /> SF: 25,000</td>
<td>Suite: 3C<br /> SF: 25,000</td>
<td>
</td>
</tr>
<?php } ?>
</table>
【问题讨论】:
-
你到底在纠结什么?
-
你有没有尝试过?你试过的代码在哪里?你想让我们为你做这件事吗?
-
感谢您提供您的代码。
-
json_decode 声明在哪里?我们需要查看您从哪里获取数据以及如何将其拉入 json_decode 以了解您在做什么。
-
你试过我的答案了吗?我会说它是最准确的答案,所需的代码最短。让我知道它是否有效,我只是好奇。
标签: php html arrays json html-table