繁体   English   中英

使用api数据创建动态表

[英]Create dynamic table with api data

我如何使我的表动态列出从api中提取的所有值,atm它仅提取1条记录并将其放入表中,其余数据置于其外部

我可能在这里想念的东西很小,但不能把手指放在上面

感谢您的帮助,非常感谢。

<?php
$trackingId = $_POST['trackingId'];
if (isset($_POST['trackingId'])) {
    $fetch = json_decode(file_get_contents(sprintf('apigoeshere', $trackingId)));
    if ($fetch->status != 'OK') {
        echo sprintf('Error: %s', $fetch->message);
    } else {
        //example how to access statistics variable
        $inactiveAccounts = $fetch->statistics->inactiveAccounts;
        echo sprintf('Inactive accounts: %d' . "<br /><br />", $inactiveAccounts);
?>
<table border="1">
        <tr>
            <th>Account name</th>
            <th>Level</th>
        </tr>
        <?php
            //example how to display all accounts username
            foreach ($fetch->accounts as $account) {
     ?>
        <tr>
                <td><?php
                echo $account->username;
        ?></td>
            <td><?php
            echo $account->currentLevel;
        ?></td>
       </tr>
</table>
    <?php
        }
     }
}
?>

没有在正确的位置关闭foreach。 使用此代码

<?php
$trackingId = $_POST['trackingId'];
if (isset($_POST['trackingId'])) {

    $fetch = json_decode(file_get_contents(sprintf('apigoeshere', $trackingId)));

    if ($fetch->status != 'OK') {
        echo sprintf('Error: %s', $fetch->message);
    } else {
        //example how to access statistics variable
        $inactiveAccounts = $fetch->statistics->inactiveAccounts;
        echo sprintf('Inactive accounts: %d' . "<br /><br />", $inactiveAccounts);
?>
<table border="1">
    <tr>
        <th>Account name</th>
        <th>Level</th>
    </tr>
    <?php
        //example how to display all accounts username
        foreach ($fetch->accounts as $account) {
?>
   <tr>
        <td><?php
            echo $account->username;
?></td>
        <td><?php
            echo $account->currentLevel;
?></td>
    </tr>
    <?php
            }
    ?>
</table>
<?php

    }
}
?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM