CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   PHP (http://www.codingforums.com/forumdisplay.php?f=6)
-   -   JSON to mysql with php (http://www.codingforums.com/showthread.php?t=259215)

mooserider2 04-29-2012 10:33 PM

JSON to mysql with php
 
Ok I understand how to get normal JSON files into php variables with json_encode(); However, the json file I'm working with looks something like this:

Code:

{"daily":
{"1319846400000":250,"131993280000000",189"},"average":
{"1319846400000":190,"131993280000000",189"}}

There are 180 different daily prices with a 180 day running average (the long row of numbers is a timestamp in ms from Jan 1, 1970).

My question is how do I import this data into a table with id, timestamp, price, 180_average, one row per day?

mooserider2 04-29-2012 11:45 PM

Perhaps I could take the array made by json_decode() and do a foreach() but it is still nested strangely. Possibly a double foreach()? Like:

Code:

foreach($out["daily"] as $myarray) {
    foreach ($myarray as $key => $value) {
   
    }
}

I don't really know where to go from there. Possibly turn each part on the array into a string and put those strings into the database. How would I do that? Sorry I have been away from php for a while

http://www.webmasterworld.com/forum88/3811.htm this is what gave me the foreach() idea.


All times are GMT +1. The time now is 03:39 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.