Hard to understand (json_encode) i'm using the code:
<?php
$query = mysql_query("SELECT * FROM messages ORDER BY ID");
while($fetch = mysql_fetch_assoc($query))
{
$titel = $fetch[title];
$post = array('items' => array( 0 => array('title' => "$title", 'description' => "$title")));
echo json_encode($post);
}
?>
Output:
{"items":[{"title":"title","description":"title"}]}
{"items":[{"title":"title","description":"title"}]}
But i want an output like:
{
"items": [
{
"title":"title",
"description":"title"
},
{
"title":"title",
"description":"title"
},
{
"title":"title",
"description":"title"
}
]
}
Can someone please help me to get an output like the code above?