2
目前我在MongoDB
收集數據的工作中PHP
表,在我MongoDB
收集有如下數據MongoDB的NumberLong顯示
> db.AETOM.find().pretty()
{
"_id" : {
"UCODE" : NumberLong("413010192215382"),
"DCODE" : NumberLong("990004908640390")
},
"Total" : 14
}
{
"_id" : {
"UCODE" : NumberLong("413010192171534"),
"DCODE" : NumberLong("990004393658160")
},
"Total" : 562
}
{
"_id" : {
"UCODE" : NumberLong("413011193047063"),
"DCODE" : NumberLong("990004298968470")
},
"Total" : 99
}
,這是我使用的顯示記錄的代碼
<?php
$m = new MongoClient();
$db = $m->selectDB('MapData');
$collection = new MongoCollection($db,'AETOM');
$cursor = $collection->find();
$cursor->limit(10);
echo "<html><head></head><body>";
$data = "<table style='border:1px solid red;";
$data .= "border-collapse:collapse' border='1px'>";
$data .= "<thead>";
$data .= "<tr>";
$data .= "<th>UCODE</th>";
$data .= "<th>DCODE</th>";
$data .= "<th>Total</th>";
$data .= "</tr>";
$data .= "</thead>";
$data .= "<tbody>";
foreach($cursor as $document) {
$data .= "<tr>";
$data .= "<td>" . $document["UCODE"] . "</td>";
$data .= "<td>" . $document["DCODE"] . "</td>";
$data .= "<td>" . $document["Total"]."</td>";
$data .= "</tr>";
}
$data .= "</tbody>";
$data .= "</table>";
echo $data;
echo "</body></html>";
?>
當我運行它
,它只顯示「總計」價值,UCODE和DCODE領域不顯示任何東西,當我與終端檢查顯示它下面的錯誤
PHP通知:未定義指數:UCODE在 /var/www/html/MongoDBT/test2.php上線23
PHP說明:未定義指數:DCODE在 /無功/網絡/ HTML/MongoDBT /第22行的test2.php
請親切地幫我解決問題。
嘗試用'$文件[ 「_ ID」 ] [「UCODE」]'和'$ document [「_ id」] [「DCODE」]'並告訴工作與否? –
是的,它工作:),非常感謝你 – Kavinda
Kavinda很高興幫助你。歡呼:) :) :) –