Fusion表响应到HTML表

问题描述 投票:0回答:1

我试图将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
1个回答
0
投票

使用json_decode来解析响应(它是有效的JSON):

<?php
$result = file_get_contents("https://www.googleapis.com/fusiontables/v1/query?sql=SELECT%20*%20FROM%201QN6e86FybBULPekKvvXd_RF1jw01H7bZAJFjhUg&key=AIzaSyAm9yWCV7JPCTHCJut8whOjARd7pwROFDQ");
$result=json_decode($result,true);
?>
<!DOCTYPE html>
<html>
<body>
<div id="page">
    <h1>A Table of Clicks</h1>

    <table class='data'>
        <thead>
            <tr>
                <th><?php echo implode('</th><th>',$result['columns']);?></th>
            </tr>
        </thead>
        <tbody>
          <?php
            foreach($result['rows'] as $row){
              echo '<tr><td>'.implode('</td><td>',$row).'</td></tr>';
            }
          ?>
        </tbody>
    </table>
    <hr />
    </div> 
</body>
© www.soinside.com 2019 - 2024. All rights reserved.