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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:15:35+00:00 2026-05-29T09:15:35+00:00

I have a small problem when I get old messages from my database. I

  • 0

I have a small problem when I get old messages from my database. I can’t use the information using the usual console.log(data.message); because this comes back undefined but when I use console.log(data);

[{"message":"Hello","time":{"sec":1328831312,"usec":699000},"user":"4f326ef17edae18d11000000"},{"message":"Heyyy","time":{"sec":1328831324,"usec":48000},"user":"4f33a3db7edae17736000000"},{"message":"afasfasd","time":{"sec":1328831966,"usec":960000},"user":"4f33a3db7edae17736000000"},{"message":"asdfasdfasdf","time":{"sec":1328831968,"usec":283000},"user":"4f33a3db7edae17736000000"},{"message":"old message","time":{"sec":1328831969,"usec":234000},"user":"4f33a3db7edae17736000000"}]

I search my database for the messages between two users and then loop through the data like this

$messages = array();
for($i=0; $i<count($cursor['messages']); $i++){
    $object = array('message'=>$cursor['messages'][$i]['message'],
                    'time'=>$cursor['messages'][$i]['time'],
                    'user'=>$cursor['messages'][$i]['user']);

    $messages[] = $object;
}
echo json_encode($messages)

I want to be able to get the users ID, message and time the message was sent so that I can append each to my chat history but I can stuck on outputting the information.

  • 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-05-29T09:15:36+00:00Added an answer on May 29, 2026 at 9:15 am

    It looks like your response is contained within an array [].

    Assuming your paste is representative you should be able to get the data you want with

    data[i].message
    

    and

    data[i].time.sec
    

    etc.

    In your JS you will want to loop up to data.length to retrieve each message.

    Edit: Looks like you’re not parsing the string after receiving it. Please try the following

    var parsedData;
    if(JSON && JSON.parse) {
        parsedData = JSON.parse(data);
    }
    else {
        parsedData = eval(data); 
    }
    
    alert(parsedData[0].message);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small problem. I am busy trying to get messages from a
I have a small problem in my code. I'm using fetch_assoc to get data
I have a small problem and I would like to get your opinion. I'm
I have a small Problem using reg. expressions with scanner here's the code: String
I have a small problem with OrmLite on Android. When I increment the database
I have a small problem in coding confusion 3x3 matrix by using matlab... I
I have a small problem in java while using generics. I have a class
have small problem, and would very much appreciate help :) I should convert byte
I have small problem with my .net 2.0 winforms application. I want to embed
I have a small problem with interfaces. Here it is in Pseudo code :

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.