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 8989327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:13:49+00:00 2026-06-15T22:13:49+00:00

I have a rather complex situation that I need to get working, for some

  • 0

I have a rather complex situation that I need to get working, for some reason I am almost there but still not quite.

In PHP I create arrays and send to it javascript through json, I am quite sure that my problem is in this part of the code.

$insertIDs = array();

foreach($recipients as $userID)
{   
            //MySQL insert removed from question 
    $insertID = mysql_insert_id();
    array_push($insertIDs, $array[$userID] = $insertID);
}


$json = array();
$json['fromID'] = $session;
$json['insertIDs'] = $insertIDs;
    $json['recipients'] = $recipients;
echo json_encode($json);

when I console.log the results of this in javascript, I get:

{ messageID: 40,
  fromID: '1',
  insertIDs: [ 44 ],
  recipients: [ '3' ] }

Now in javascript when I try to access the insertIDs by the userID which I set it to be in the php above, I just get undefined as a result. How can I do this so I can access each insertID by the userID?

for example: json.insertIDs[userID]

if I simply call it by: json.insertIDs[0] it does return the first insertID, however when there are multiple I need to be able to have an easy way to access each usersID insertID.

  • 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-15T22:13:50+00:00Added an answer on June 15, 2026 at 10:13 pm

    I’m not quite sure what you are trying to do, since in the forloop $insertID is always the same value but:

    It seems like json.InsertIDs is an array of the form json.InsertIds = Array(44);

    Where as you want it to be Array(3 => 44)

    try changing your forloop from

    foreach($recipients as $userID){   
    $insertID = mysql_insert_id();
    array_push($insertIDs, $array[$userID] = $insertID);
    }
    

    to

    foreach($recipients as $userID){   
        $insertID = mysql_insert_id();
        $insertIDs[$userID] = $insertID;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a number rather large, complex xml documents that I need to loop
Have a (rather complex) app that works fine on iOS 4 but fails on
I have a window that contains several rather complex views. Right now, I'm using
I have a PHP class that stores a complex multidimensional array, and rather than
I have some rather odd behavior in my D program that I've narrowed down
I have a rather complicated Binding situation. I have a solution that I created
I have a legacy class that is rather complex to maintain: class OldClass {
I have a rather basic C++ question: Consider a function that takes some input
I have a rather complex formula that I want to recreate with code, I
I have a rather complex legacy ASP.Net application that is under continuous development, and

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.