PHP Array and Google Analytics V3 API

╄→гoц情女王★ 提交于 2019-12-04 17:34:41

To get you on your way use

$data [rows][$i][$j][columnHeaders] [0][name]
$data [rows][$i][$j][columnHeaders] [1][name]

and for rows use something like

$data [rows][0][1]

You will have to get the variable via increment with something like:

var =(count($data [columnHeaders]));

   for ($i='0'; $i<=$var; $i++) {
    echo '.$data [columnHeaders] [$i][name].';}

This should get you on your way towards building your table. Good Luck!

The issue is in your foreach for the table body rows. You appear to have missed the rows out. Wrap it in another loop to print out tr around the set of tds.

This is what I used for printing out a table of analytics data:

$data = $analytics->data_ga->get('ga:' . $profileId, $dateFrom, $dateTo, $metrics, array('dimensions' => $dimensions));

<table>
        <thead>
            <tr>
                <?php 
                    foreach ($data->columnHeaders as $header) {
                        $headerName = ucwords(preg_replace('/(\w+)([A-Z])/U', '\\1 \\2', str_replace('ga:', '', $header->name)));
                        print '<th>';
                        printf('%s', $headerName);
                        print '</th>';
                    }
                ?>
            </tr>
        </thead>
        <tbody>
        <?php 
            foreach ($data->rows as $row) {
                print '<tr>';
                foreach ($row as $cell) {
                    print '<td>';
                    printf('%s', $cell);
                    print '</td>';
                }
                print '</tr>';
            }
        ?>
    </tbody>
 </table> 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!