{"id":1048,"date":"2013-07-27T10:19:55","date_gmt":"2013-07-27T10:19:55","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=1048"},"modified":"2022-02-17T07:14:03","modified_gmt":"2022-02-17T07:14:03","slug":"dynamic-json-file","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/php\/json\/dynamic-json-file","title":{"rendered":"Dynamic json file"},"content":{"rendered":"<p>\nUse a php file which simply outputs json data. &nbsp;E.g.\n<\/p>\n<pre>\r\n<code>\r\n&lt;?php\r\n\r\n\/\/Get some data from a table\r\n$my_array = array();\r\n$result1 = @mysql_query(&quot;SELECT field1, field2 FROM table1 ORDER BY field1&quot;);\r\nwhile ($row = @mysql_fetch_array($result1))\r\n{\r\n   $my_array[] = $row;\r\n}\r\n\r\n\/\/Add it and some other data to an array\r\n$data = array(\r\n  &quot;results&quot; =&gt; array(\r\n    &quot;my_field1&quot; =&gt; &quot;abcd&quot;,\r\n\t\t&quot;my_array&quot; =&gt; &quot;my_array&quot;,\r\n    &quot;my_manual_array&quot; =&gt; array(\r\n      &quot;item&quot; =&gt;\r\n      array(\r\n        array(\r\n          &quot;item_field1&quot; =&gt; &quot;123456&quot;,\r\n          &quot;item_field2&quot; =&gt; &quot;Hello 1&quot;\r\n        ),\r\n        array(\r\n          &quot;item_field1&quot; =&gt; &quot;7890&quot;,\r\n          &quot;item_field2&quot; =&gt; &quot;Hello 2&quot;\r\n        )\r\n      )\r\n    )\r\n  )\r\n);\r\n\r\n\/\/Output it as json\r\necho json_encode($data);\r\n?&gt;\r\n<\/code><\/pre>\n<p>\n&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Use a php file which simply outputs json data. &nbsp;E.g. &lt;?php \/\/Get some data from a table $my_array = array(); $result1 = @mysql_query(&quot;SELECT field1, field2 FROM table1 ORDER BY field1&quot;); while ($row = @mysql_fetch_array($result1)) { $my_array[] = $row; } \/\/Add it and some other data to an array $data = array( &quot;results&quot; =&gt; array( &quot;my_field1&quot; [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[109],"tags":[],"class_list":["post-1048","post","type-post","status-publish","format-standard","hentry","category-json"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/1048","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/comments?post=1048"}],"version-history":[{"count":4,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/1048\/revisions"}],"predecessor-version":[{"id":1337,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/1048\/revisions\/1337"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=1048"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=1048"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=1048"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}