【问题标题】:Json to table php empty recordsJson表php空记录
【发布时间】:2021-11-21 15:02:42
【问题描述】:

我想将 json 输出显示到 html 表,但该表有很多空记录。 (下图)

<?php
$json2=file_get_contents("****" . $row["Kenteken2"]);
$data2 =  json_decode($json2);

     if (strpos($data2[0], 'model') !== false) {
     echo '<h4>Zelfde serie voertuigen</h4>';
    // Open the table
     echo '<table class="GeneratedTable">';
     echo '<thead><tr><th>Niet DB</th><th>In DB</th></tr></thead><tbody><col style="width:50%" span="2" />';

    // Cycle through the array
                
    foreach ($data2 as $vrt) {
        

        // Output a row
        echo '<tr>';
        echo '<td><a href="/****.php?ktk='.$vrt->model.'&via=ktk.net/'.$row["Kenteken2"].'&model='.$row["MerkModel"].'" target="_blank">'.$vrt->model .'</a></td>';
        echo '<td><a href="/****.php?ID='.$vrt->id.'">'.$vrt->model2 .'</a> '.$vrt->dienst . ' ' . $vrt->bijzonderheden .'</td>';
        echo "</tr>";

    }
    // Close the table
     echo "</tbody></table>";
}   

?>

结果:

【问题讨论】:

  • 你能扩展一下这个问题吗?我实际上不确定你在问什么。
  • 对不起,问题是行之间 有空行。我想删除这个空行。
  • 当在“In DB”处具有值时,您会在标题“Niet DB”下看到空行。我想在表中删除这个空行。所有的文字都很好。
  • 所以你想要一列从上到下列出数据库中的值,一列列出不存在的值,你不关心这意味着一行将包含两条记录彼此没有任何关系?
  • 对不起,我想要 2 列。但里面没有空行。

标签: php html json html-table


【解决方案1】:

如果你想要 1 张桌子:

我会创建一个 foreach 来创建 2 个不同的数组 $neit_db[] 和 $in_db[] 然后我会做一个 while 循环,直到两个数组都为空,我会在它们之间进行 ping pong

如果你想要 2 张桌子:

我会创建一个 foreach 来创建 2 个不同的数组 $neit_db[] 和 $in_db[] 我会 while 循环为您放置在彼此旁边的每个表单独循环遍历每个数组。

【讨论】:

    猜你喜欢
    相关资源
    最近更新 更多
    热门标签