我目前不知道如何做到这一点,需要帮助,但我目前正在构建一个 ionic 应用程序,并在通过 PHP 脚本取回该信息时将信息存储在数据库中,我正在接收我想要的 JSON转换为格式良好的 HTML 表格
这是我的 PHP
<?php
header("Access-Control-Allow-Headers: Content-Type");
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
header("Access-Control-Allow-Origin: *");
$host = "****";
$user = "*****";
$password = "";
$database = "holes";
$connect = mysqli_connect($host,$user,$password,$database) or die("Problem connecting.");
$result = mysqli_query($connect, "SELECT * from hole18") or die("Bad Query.");
mysqli_close($connect);
$results = array();
while($row = mysqli_fetch_assoc($result))
{
$results[] = $row;
}
echo json_encode($results);
?>
这是 Json 输出:
[{"index":"1","Par":"4","FIR":"1","GIR":"1","Score":"3","puttsno":"1","bunkershit":"0","oob":"0"}]
请帮助我
最佳答案
试试这个
<table>
<?php
$json_result = json_encode($results);
$json_dec_result = json_decode( $json_result );
if ( !empty( $json_dec_result) )
{
foreach ($json_dec_result as $field_name => $field_value)
{
?>
<tr>
<td>
<?php echo $field_name;?>
</td>
<td>
<?php echo $field_value;?>
</td>
</tr>
<?php
}
}
?>
</table>
关于javascript - 通过 PHP 将 JSON 输出转换为 HTML 表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36822685/