This is my php file from where i want to get json file data and show it in the table form in php.I am getting error on browser while getting values of expense table from json file ?
The error i am getting is : Notice: Undefined index: amounts in C:\xampp\htdocs\jsontophptable\table.php on line 20
<!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>
This is my json file from where i want to get nested data: I want to get expense table data in json as seperate table in php and sales table seperate.How to do that?
{
"Expense_Details_DataBase" : {
"24-10-2018--02:15:46 PM" : {
"amounts" : "36",
"details" : "tree",
"email" : "a@gmail.com"
}
},
"Sales_Details_DataBase" : {
"24-10-2018--03:23:08 PM" : {
"email" : "b@hotmail.com",
"sale" : 1040
},
"24-10-2018--03:23:58 PM" : {
"email" : "b@hotmail.com",
"sale" : 5010
},
"24-10-2018--12:41:30 PM" : {
"email" : "a@gmail.com",
"sale" : 120
}
}
}
This is my new php file after editing: The table after this edit is not showing any data it is empty. how to fix that? .And also I want to get date and time also in table how to do that?
<!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>