Single MySQL table into multidimensional JSON with PHP -
i have table in database called timeline_entries
. table contains following fields: id
, headline
, text
, startdate
, type
, media
, caption
, credit
. id
field used referencing individual entries through cms.
i have worked out how export data json , save file, i'm struggling find way format following structure;
{ "timeline": { "headline":"value", "type":"default", "startdate":"value", "text":"value", "asset": { "media":"value", "credit":"value", "caption":"value" }, "date": [ { "startdate":"value", "type":"", "headline":"value", "text":"value", "asset": { "media":"value", "credit":"value", "caption":"value" } }, { "startdate":"value", "type":"", "headline":"value", "text":"value", "asset": { "media":"value", "credit":"value", "caption":"value" } }, { "startdate":"value", "type":"", "headline":"value", "text":"value", "asset": { "media":"value", "credit":"value", "caption":"value" } }, ] } }
(please ignore shoddy indenting, i'm still getting used this!)
i've had replace actual data 'value' of data quite long.
as can see, first set of data needs formatted different rest, remainder of sets placed within "date" , media
, caption
, credit
fields need structured subset of "asset".
there more rows of data 4 or so, can't hardcode anything.
can me format it? if it's possible, i'd keep database side simple possible, can changed if have to. perhaps i'm going wrong? appreciated.
thank you.
formatting of json isn't @ important other aesthetics, have thought of using php json_encode method , have done it?
Comments
Post a Comment