【发布时间】:2014-01-19 16:20:40
【问题描述】:
我正在尝试将 Fusion Table SQL 响应放入基本的 HTML 表中。这既适用于搜索引擎素材,也适用于谷歌电子表格及其 importhtml 功能。
将响应转换为表格的 foreach 出现了一些不寻常的响应,例如一次 1 个字符?此外,响应似乎被格式化为可以轻松制作成数组的东西,但我的努力是徒劳的。现在已经研究了两天多,我敢打赌有人比我更了解格式并且知道答案吗?
<?php
$result = file_get_contents("https://www.googleapis.com/fusiontables/v1/query?sql=SELECT%20*%20FROM%201QN6e86FybBULPekKvvXd_RF1jw01H7bZAJFjhUg&key=AIzaSyAm9yWCV7JPCTHCJut8whOjARd7pwROFDQ");
?>
<!DOCTYPE html>
<html>
<body>
<div id="page">
<h1>A Table of Clicks</h1>
<table class='data'>
<thead>
<tr>
<th>date</th>
<th>fundraiser</th>
<th>name</th>
<th>link</th>
<th>price</th>
<th>image</th>
<th>ip</th>
<th>merchant</th>
</tr>
</thead>
<tbody>
<?php
list($part1, $part2) = explode(' "rows": [[', $result);
$rows = explode(' ], [', $part2);
echo $rows[0]."<br>";
foreach ($rows as $row) {
{
//$array = array($row);
///var_dump($array);
$boxes = explode(",", $row);
foreach ($boxes as $box) {
echo "
<tr>
<td>".$box[0]."</td>
<td>".$box[1]."</td>
<td>".$box[2]."</td>
<td>".$box[3]."</td>
<td>".$box[4]."</td>
<td>".$box[5]."</td>
<td>".$box[6]."</td>
<td>".$box[7]."</td>
</tr>";
}
}
}
?>
</tbody>
</table>
<hr />
</div>
</body>
【问题讨论】:
标签: php html-table google-fusion-tables