php - Mongodb and Twitter array -


code :

$m = new mongoclient(); $db = $m->selectdb('twitter'); $collection = new mongocollection($db, 'status');   $cursor = $collection->find();   foreach ($cursor $document) {   echo $document['statuses'][0]['text']; } 

array :

array (     [_id] => mongoid object     (         [$id] => 123     )      [statuses] => array     (         [0] => array             (             [text] => tweet no 1             )         [1] => array             (             [text] => tweet no 2             )         [1] => array             (             [text] => tweet no 3             )     ) ) 

the output : tweet no 1.

how whole 'text' array? should return 'tweet no 1, tweet no 2, tweet no 3' instead.

i've tried echo $document['statuses']['text'] doesn't work.

right query returning collection, iterating correctly. issue is collection single document , printing first status in document:

foreach ($cursor $document) {     // here $document = {_id: 123, statuses:[{text:'tweet no 1'},{text:'tweet no 2'},{text:'tweet no 3'}]}     // here printing first status            echo $document['statuses'][0]['text']; } 

your document has array of statuses, want loop through array:

foreach ($cursor $document) {     foreach($document["status"] $status) {         echo $status['text'];     } } 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -