php - API-call JSON into MySQL -


i'm working on research project want insert json file (from api-call) mysql database. found multiple examples don't know begin because there multiple objects , arrays. second problem columns , rows separate arrays (i think?).

our goal fill (daily, hourly, etc) database looks likes (it example , have multiple items):

----------------------------------- | date | value2 | value3 | value4 | ----------------------------------- | 01-01-2015 | 123 | 1234 | 12345 | ----------------------------------- | 02-01-2015 | 343443 | 4w3543422 | fref4rw4 |  ----------------------------------- | 03-01-2015 | 234422r | wrfrw3434 | 2432rfr42324 | ----------------------------------- 

question how can values json (which isn't static: there 7 days, less , more)? begin?

i think using foreach loop after decoding json php array can worked out.

<?php $array = json_decode($json_data,true); $sql_inserts = array(); foreach($array['reportitem']['rows']['r'] $row)     {         $sql_inserts[] = "('".$row[c][0]."','".$row[c][1]."','".$row[c][2]."','".$row[c][3]."')";     } $insert_values = implode("'",$sql_inserts); $sql = "insert table_name (date,value2,value3,value4) $insert_values ;"; ?> 

and sql statement created json array's data.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -