我有这样的代码:
$url='MY API';
$json = json_decode( file_get_contents( $url ) );
$res=$json->results;
foreach( $res as $obj ){
$values=$obj->values;
foreach( $values as $o ){
echo $o->name . ' ' . $o->value . ' ' . $o->objectTypeId . '<br />';
}
}获取以下输出:
country Germany 0-2
title_no_dropdown ADP, ECM Intro 0-1
presented_by PMI Document Solutions, Inc. 0-1
city Munich 0-1
website http://www.pmi-ny.com 0-1
start_date October 24 0-1
time 1200 0-1
type Webinar 0-1
description this is a test 0-2
email bob@hotmail.com 0-1
link Link to partner event 0-1
country United States 0-2
title_no_dropdown ADP, Work Smart from the Start 0-1
state NY 0-1
presented_by PMI Document Solutions, Inc. 0-1
city Corning 0-1
website http://www.pmi-ny.com 0-1
start_date September 24 0-1
time 1000 0-1
type Infoseminar 0-1
description This is a test 0-2
email likwid2@hotmail.com 0-1如何将$o->值作为变量获取,或者以某种方式控制顺序,以便将它们添加到表格单元格中。另外,如何使用这些变量创建该表。谢谢。
发布于 2021-09-04 22:02:50
从这里开始:https://www.w3schools.com/html/html_tables.asp -了解表是如何构建的……基本上就是在打印数据之前和期间添加html……
示例:(我做了一些解释并删除了一个循环,因为我没有您的值,并且想要演示一个可以与复制/粘贴一起工作的代码:)
<table>
<tr>
<th>Country</th>
<th>Title</th>
<th>City</th>
</tr><?php
//foreach( $res as $obj ){
$values= ["country1" => "aaa","title1"=>"bbbb","city1" => "tel-aviv"];
?><tr><?php
foreach( $values as $o ){
echo "<td>" . $o . '</td>';
}
?><tr><?php
// }
?></table>即使你把另一个循环带回来...请记住新行和新<td>何时开始。
知道东西的位置是很重要的,因为我们是在循环遍历值。因此,<th>将处于循环之外,因为它们只出现一次……而<tr>的<td>取决于数据的放置方式。
在这上面打上一些css,你就好了!
https://stackoverflow.com/questions/69059052
复制相似问题