How to output all results from MongoDB's find() into jQuery's html()?
PHP
<?php
$dbhost = 'username:password@127.x.xx.x:27017/';
$dbname = 'my_database';
$m = new MongoClient("mongodb://$dbhost");
$db = $m->$dbname;
// specify the collection
$collection = $db->myCollection;
// define the query
$query = $collection->find(array("field1.subfield1" => "my value"));
foreach($query as $result) {
echo $result['field3'] . " - " . $result['field4'] . "<br>";
}
?>
When accessing the PHP file directly would display:
field3 value - field4 value
field3 value - field4 value
How would I get the same output via jQuery so that the contents of a div
would show the above results, eg:
jQuery
$.getJSON("http://path/to/file.php", {cid: href, format: 'json'},
function(results){
$("#my_div").html(results);
});
No comments:
Post a Comment