How to display json stored in a session?
How to display json stored in a session?
Thanks in advance for your help ...
I have the following json stored in $_SESSION['data']:
[{"Title":"title1", "Value":"valueA"},
{"Title":"title2", "Value":"valueB"},
{"Title":"title3", "Value":"valueC"}
]
How can I display this in a table with two columns Title and Value?
I thought I can do the following, but didn't work:
$(document).ready(function() {
$('#example').dataTable( {
"aData": <?php echo $_SESSION['data']; ?>
} );
} );
Here is how I have the html:
Title
Value
Title
Value
I have the following json stored in $_SESSION['data']:
[{"Title":"title1", "Value":"valueA"},
{"Title":"title2", "Value":"valueB"},
{"Title":"title3", "Value":"valueC"}
]
How can I display this in a table with two columns Title and Value?
I thought I can do the following, but didn't work:
$(document).ready(function() {
$('#example').dataTable( {
"aData": <?php echo $_SESSION['data']; ?>
} );
} );
Here is how I have the html:
Title
Value
Title
Value
This discussion has been closed.
Replies
function toJSArray($json) {
$a = json_decode($json);
$jsArr = "[";
$cma = "";
foreach ($a as $i) {
$jsArr .= "{$cma}["; //<
$cma = "";
foreach ($i as $k=>$v) {
$jsArr .= "{$cma}\"$v\"";
$cma = ",";
}
$jsArr .= "]";
$cma = ","; //<
}
$jsArr .= "]";
return $jsArr;
}