繁体   English   中英

如何使用php在表格中显示MongoDB数据

[英]How to show MongoDB data in a table using php

我正在用PHP查询MongoDB,并且希望在表中显示集合的所有数据。

这是我要拉回的数据的部分样本:

Array (
  [0] => Array (
  [transactions] => Array (
    [_id] => 729cfe7c462089e204000000
    [propertyId] => 729cfe01462089e104000000
    [chargedTo] => tenant
    [tenantId] => 729cfe5f462089c104000000
    [category] => rent
    [amount] => 1000
    [paymentMethod] => cheque
    [datedAt] => 2013-01-01
    [status] => paid
    [attachmentUrl] =>
    [attachmentName] =>
    [description] =>
    [emailTenant] => 0
    [paidAt] =>
    [createdAt] => 2013-03-23T00:49:48.350Z
    [accountId] => 729cfc194620897c03000000
    [alert] =>
    )
  )
[1] => Array (
  [transactions] => Array (
    [_id] => 729cfe93462089ea04000000
    [propertyId] => 729cfe01462089e104000000
    [chargedTo] => tenant
    [tenantId] => 729cfe5f462089c104000000
    [category] => rent
    [amount] => 5000
    [paymentMethod] => cheque
    [datedAt] => 2013-03-22
    [status] => paid
    [attachmentUrl] =>
    [attachmentName] =>
    [description] =>
    [emailTenant] => 0
    [paidAt] =>
    [createdAt] => 2013-03-23T00:49:48.350Z
    [accountId] => 729cfc194620897c03000000
    [alert] =>
    )
  )
  .
  .
  .
[n] => Array (
  [transactions] => Array (
    [_id] => 729cfea54620897c03000001
    [propertyId] => 729cfe01462089e104000000
    [chargedTo] => tenant
    [tenantId] => 729cfe5f462089c104000000
    [category] => rent
    [amount] => 2222
    [paymentMethod] => Paypal
    [datedAt] => 2013-03-05
    [status] => paid
    [attachmentUrl] =>
    [attachmentName] =>
    [description] =>
    [emailTenant] => 0
    [paidAt] =>
    [createdAt] => 2013-03-23T00:49:48.350Z
    [accountId] => 729cfc194620897c03000000
    [alert] =>
    )
  )
)

如何获取所有这些数据以显示在PHP的表中?

<?php
$db = new Mongo();
$query = $db->dbname->collection->find();

echo '<pre>';

foreach ( $query as $current )
    print_r($current);

echo '</pre>';
?>

应该工作正常。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM