I write SQL in postgres 9.3 which works almost perfectly:
SELECT type_id, to_json(array_agg(row(value, id))) AS json FROM sub_types GROUP BY type_id
The result table looks:
type_id | json
1 | [{"f1":"something", "f2":7}, ...]
2 | [{"f1":"something new", "f2":2}, ...]
I am trying to do that the result looks like:
type_id | json
1 | [{"value":"something", "id":7}, ...]
2 | [{"value":"something new", "id":2}, ...]
Basic idea is to to write code (PHP) something close to this: rows = pdo_call_select
rows = pdo_call_select
foreach (rows as row)
{
print '<span data-id="row->id">'
foreach (row->json as otherfields)
print '<input value="otherfields->value" ...'
...
and my table is:
id | type_id | value
1 3 something
2 2 blabla
3 3 something new
4 1 ok
...