My table looks like:
id | title | link | kind
------------------------
1 link1 http one
4 link2 http two
2 link9 http one
I want to give back a JSON Array (JSON parsing is not the problem!) which looks like:
one
- link1, http
- link9, http
two
- link2, http
The kind-colum is dynamic so I do not know the actual string. (But it is never (null)!)
What I have:
$links = array();
while($row = mysql_fetch_object($result)) {
$link = array(
'title' => $row->title,
'link' => $row->link,
'kind' => $row->kind
);
$links[] = $link;
}
echo json_encode($links);
That’s one array with all columns for each element.
Use $row->kind as an index into the top level array.