Any help would be appreciated!
I've been going at this for a little bit now and can't seem to get this to work. What am I doing wrong?
I'm trying to get the output of a JSON structure below using php. Take a look at the differences with the outputs below!
$mysqli = new mysqli('localhost','root','1234','root');
$records = array();
if ($result = $mysqli->query("SELECT * FROM users")) {
while($row = $result->fetch_array(MYSQL_ASSOC)) {
$records[] = $row;
}
$json = json_encode($records, JSON_PRETTY_PRINT);
}
file_put_contents('records.js', $json, FILE_APPEND);
What it's outputting now:
[
{
"id": "2",
"volume": "volume1",
"name": "a",
"content": "<img src="image_2.jpg">",
"cssanimate": "bounce"
},
{
"id": "2",
"volume": "volume1",
"name": "a",
"content": "<img src="image_2.jpg">",
"cssanimate": "bounce"
},
{
"id": "2",
"volume": "volume1",
"name": "a",
"content": "<img src="image_2.jpg">",
"cssanimate": "bounce"
}
]
What I want the output to be:
var data = [{
{
tags: [{
"id": "2",
"volume": "volume1",
"name": "a",
"content": "<img src="image_2.jpg">",
"cssanimate": "bounce"
}]
},
{
tags: [{
"id": "2",
"volume": "volume1",
"name": "a",
"content": "<img src="image_2.jpg">",
"cssanimate": "bounce"
}]
},
{
tags: [{
"id": "2",
"volume": "volume1",
"name": "a",
"content": "<img src="image_2.jpg">",
"cssanimate": "bounce"
}]
}
}]
$data?tagskey - you should add it by yourself. No one will do it for you.[and{in json? Are you sure you need array of objects of objects? I bet this is invalid structure.