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

  • Home
  • SEARCH
  • 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 9202015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:09:32+00:00 2026-06-17T23:09:32+00:00

This works when we do this: $db = $connection->messages; $collection = $db->messagesCollection; $messageArray =

  • 0

This works when we do this:

$db = $connection->messages;
$collection = $db->messagesCollection;
$messageArray = $collection->find(array('IDto' => '4'));
foreach($messageArray as $messageData){
    $messageFrom = $messageData['IDfrom'];
    $messageTo = $messageData['IDto'];
    $messageTitle = $messageData['messageTitle'];
    $messageIfRead = $messageData['ifRead'];    
}

$JSONData = array('true', $messageFrom, $messageTo, $messageTitle, $messageIfRead); 
echo $_GET['callback']."(".json_encode($JSONData).")";

But when we do this:

$db = $connection->messages;
$collection = $db->messagesCollection;
$messageArray = $collection->find(array('IDto' => '4'));
$JSONData = array('true', $messageArray); 
echo $_GET['callback']."(".json_encode($JSONData).")";

and in the Javascript do this:

$.getJSON("mySite.com/pullData/getMail.php?callback=?",{
request: requestVar},
function(recievedData) {
    alert(recievedData);
})

We get an alert of true, [object Object]
When using console log we get Object {}

How do we send that table data correctly?

  • 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-17T23:09:33+00:00Added an answer on June 17, 2026 at 11:09 pm

    I believe your biggest problem is the MongoCursor:

    $messageArray = $collection->find(array('IDto' => '4'));
    $JSONData = array('true', $messageArray); 
    echo $_GET['callback']."(".json_encode($JSONData).")";
    

    You are trying to encode an object of MongoCursor there, hence the string representation is [object Object].

    Try:

    $messageArray = $collection->find(array('IDto' => '4'));
    $JSONData = array('true', iterator_to_array($messageArray)); 
    echo $_GET['callback']."(".json_encode($JSONData).")";
    

    Instead. All find functions in MongoDB return a MongoCursor, the reason why your first code works is because you iterate the cursor building up your objects:

    foreach($messageArray as $messageData){
        $messageFrom = $messageData['IDfrom'];
        $messageTo = $messageData['IDto'];
        $messageTitle = $messageData['messageTitle'];
        $messageIfRead = $messageData['ifRead'];    
    }
    

    Note as well that the default json_encode of a document will contain objects, such as MongoId and MongoDate that do not encode too well into reusable JSON syntax. As such you will need to handle these types yourself.

    Edit

    Maybe a better way is to actually redo the indexes manually:

    $messageArray = $collection->find(array('IDto' => '4'));
    $d = array();
    foreach($messageArray as $row){
        $d = $row;
    }
    
    $JSONData = array('true', $d); 
    echo $_GET['callback']."(".json_encode($JSONData).")";
    

    This way you will have a 0 based incrementing index instead of the ObjectId as each index base.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This works. $(document).ready(function(){ $(.items article).click(function(){ window.location=$(this).find(a).attr(href); return false; }); }); However , when the
I've got collection of words, and i wanna create collection from this collection limited
This works but for some reason the comma is missing. data gets inserted as
This works: <cfdirectory action=list name=qry directory=C:\inetpub\wwwroot\Atlas\ > </cfdirectory> <cfdump var=#qry#> So I know that
This works in chromium (and I assume every other major browser) -html- <invalid></invalid> -css-
This works when I have only one state code as a parameter. How can
This works: require 'csv' file = CSV.open(filename) puts file.shift This does not: require 'csv'
This works when I used a rectangle as the food but now I'm trying
This works, but when I hover the first time, nothing loads. When I mouse
this works: //delegate Parallel.For(1023456789, 1033456789, delegate(long i) { if (i % 10000000 == 0)

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.