Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8013709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:42:20+00:00 2026-06-04T19:42:20+00:00

Here is my array; $json = ‘ { 1:{ Device_ID:a9a3346be4375a92, Date:2012-05-31, Time:15:22:59, Latitude:51.4972912, Longitude:0.1108178

  • 0

Here is my array;

    $json = '
{
    "1":{
        "Device_ID":"a9a3346be4375a92",
        "Date":"2012-05-31",
        "Time":"15:22:59",
        "Latitude":"51.4972912",
        "Longitude":"0.1108178"
    },
    "2":{
        "Device_ID":"a9a3346be4375a92",
        "Date":"2012-05-31",
        "Time":"15:52:07",
        "Latitude":"51.4988357",
        "Longitude":"0.1222859"
    }
}';

It’s decoded like this: $array = json_decode($json);

I am trying to now insert into a database all the $items in the above array; so i would like to store in a single record all the data within 1, and in a second record all the values within 2.

The idea is i will never know the size of the array so it could have 100 $items.

How would this be done?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T19:42:22+00:00Added an answer on June 4, 2026 at 7:42 pm

    Try something like this:

    $item_array = json_decode($json, true);
    $insert_query = "INSERT INTO items (column1,column3) VALUES ";
    $i = 0;
    $array_count = count($item_array);
    
    foreach($item_array as $item) {
     $end = ($i == $array_count) ? ';' : ',';
     $insert_query .= "('".$item['date']."','".$item['device_id']."')" . $end;
     $i ++;
    }
    
    mysql_query($insert_query);
    

    The resulting query will look something like:

    INSERT INTO items (column1,column3) VALUES ('asdf',123),('asdfe',1234);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Json array that contains latitude and longitude coordinates. Here's a sample:
How to get array data from json in c#? Here is the ajax code
The problem here is pretty self-evident from the resulting JSON array at the bottom.
I am trying to sort a multidimensional JSON array (called jsontest here) using JQuery
I need help here in my practice program. I have a json array: myData=[{plank_number:1,thickness:5,width:7,length_t:8,quantity:1},
I'm using Jackson to deserialize a json array into some objects. Here's my class:
I want to get the value of json array using .each here's where I
I have such JSON array in file var jsonfromfile = [ [Date.UTC(2004, 1, 3),
I need assistance in accessing a nested array located my JSON Data Set. Here
I am getting Error java.lang.NumberFormatException: For input string: passing JSON array to Spring-MVC.. Here

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.