如何将嵌套的json数据放入php表中?json中的两个不同的表?
这是我的php文件,我想从中获取json文件数据,并将其显示在php的表格中。从json文件获取费用表的值时,我在浏览器上遇到错误 我得到的错误是: 注意:未定义索引:第20行C:\xampp\htdocs\jsontophtable\table.php中的金额如何将嵌套的json数据放入php表中?json中的两个不同的表?,php,json,Php,Json,这是我的php文件,我想从中获取json文件数据,并将其显示在php的表格中。从json文件获取费用表的值时,我在浏览器上遇到错误 我得到的错误是: 注意:未定义索引:第20行C:\xampp\htdocs\jsontophtable\table.php中的金额 <!DOCTYPE html> <html> <body> <?php $url = 'accountbook.json'; // path to you
<!DOCTYPE html>
<html>
<body>
<?php
$url = 'accountbook.json'; // path to your JSON file
$data = file_get_contents($url); // put the contents of the file into a variable
$characters = json_decode($data,true); // decode the JSON feed
?>
<table>
<tbody>
<tr>
<th>Amount </th>
<th>Detail</th>
<th>Email</th>
</tr>
<?php foreach ($characters as $character) : ?>
<tr>
<td> <?php echo $character['amounts']."\n" ?> </td>
<td> <?php echo $character['details']."\n"; ?> </td>
<td> <?php echo $character['email']."\n;"?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</body>
</html>
这是我编辑后的新php文件:编辑后的表没有显示任何数据,它是空的。如何解决这个问题。我还想把日期和时间也记在表格里,怎么做
<!DOCTYPE html>
<html>
<head>
<style>
table, td, th {
border: 1px solid black;
}
table {
border-collapse: collapse; width: 30%;
text-align: center;
}
th {
background-color: #4CAF86;
color: white;
height: 70px;
text-align: center;
padding: 6px;
}
td{
padding: 6px;
border-bottom: 1px solid #ddd;
}
tr:hover {background-color: #f5f5f5;}
</style>
</head>
<body>
<?php
$url = 'accountbook.json'; // path to your JSON file
$data = file_get_contents($url); // put the contents of the file into a variable
$characters = json_decode($data,true); // decode the JSON feed
?>
<table>
<table align="center">
<tbody>
<tr>
<th>Amount </th>
<th>Detail</th>
<th>Email</th>
</tr>
<?php
if(isset($characters['Expense_Details_DataBase'])){
foreach ($characters['Expense_Details_DataBase'] as $character) :
?>
<tr>
<td> <?php echo $character['amounts']."\n" ?> </td>
<td> <?php echo $character['details']."\n"; ?> </td>
<td> <?php echo $character['email']."\n;"?></td>
<?php print_r($character); ?>
</tr>
<?php endforeach;
} ?>
</tbody>
</table>
</body>
</html>
表,td,th{
边框:1px纯黑;
}
桌子{
边界塌陷:塌陷;宽度:30%;
文本对齐:居中;
}
th{
背景色:#4CAF86;
颜色:白色;
高度:70像素;
文本对齐:居中;
填充:6px;
}
运输署{
填充:6px;
边框底部:1px实心#ddd;
}
tr:hover{背景色:#f5;}
数量
细节
电子邮件
试试这个
<!DOCTYPE html>
<html>
<body>
<?php
$url = 'accountbook.json'; // path to your JSON file
$data = file_get_contents($url); // put the contents of the file into a variable
$characters = json_decode($data,true); // decode the JSON feed
?>
<table>
<tbody>
<tr>
<th>Amount </th>
<th>Detail</th>
<th>Email</th>
</tr>
<?php
if(isset($characters['Expense_Details_DataBase'])){
foreach ($characters['Expense_Details_DataBase'] as $character) :
?>
<tr>
<td> <?php echo $character['amounts']."\n" ?> </td>
<td> <?php echo $character['details']."\n"; ?> </td>
<td> <?php echo $character['email']."\n;"?></td>
</tr>
<?php endforeach;
} ?>
</tbody>
</table>
</body>
</html>
数量
细节
电子邮件
打印($character)
并查看您实际拥有的内容。该错误表示索引不存在。我很惊讶这里没有详细信息
和电子邮件
通知。请阅读我的评论,并回答您的任何问题。只需多次注释请更正我的代码
对你的问题没有帮助我在实现suggestionArray([24-10-2018--02:15:46 PM]=>数组([amounts]=>36[details]=>tree[email]=>a@gmail.com)数组([24-10-2018--03:23:08 PM]=>数组([email]=>b@hotmail.com [销售]=>1040)[2018年10月24日--03:23:58下午]=>Array([电子邮件]=>b@hotmail.com[销售]=>5010)[2018年10月24日--下午12:41:30]=>Array([电子邮件]=>a@gmail.com[sale]=>120)可能是垃圾数据格式的副本。日期和时间作为对象键?Jesus Lara感谢您的帮助,但您的代码不起作用。它显示的是空表
<!DOCTYPE html>
<html>
<body>
<?php
$url = 'accountbook.json'; // path to your JSON file
$data = file_get_contents($url); // put the contents of the file into a variable
$characters = json_decode($data,true); // decode the JSON feed
?>
<table>
<tbody>
<tr>
<th>Amount </th>
<th>Detail</th>
<th>Email</th>
</tr>
<?php
if(isset($characters['Expense_Details_DataBase'])){
foreach ($characters['Expense_Details_DataBase'] as $character) :
?>
<tr>
<td> <?php echo $character['amounts']."\n" ?> </td>
<td> <?php echo $character['details']."\n"; ?> </td>
<td> <?php echo $character['email']."\n;"?></td>
</tr>
<?php endforeach;
} ?>
</tbody>
</table>
</body>
</html>