2016-07-04 6 views
0

ich PHP-Code haben für MongoDB Sammlungsdaten zu php tisch angezeigt wird, wenn ich es laufen sie zeigen keine Ausgabe,MongoDB Sammlung Daten zu Php Tabelle Ausgabe

bitte so freundlich sein, diese

zu sortieren hier ist mein Code

<?php 

     $m = new MongoClient(); 
     $db = $m->selectDB('MapData'); 
     $collection = new MongoCollection($db,'ETom4'); 

     $cursor = $collection->find(); 
     //echo "<html><head><body>"; 
     echo "<table>"; 
     foreach($cursor as $doc) { 
      echo "<tr>"; 
       echo "<td>" . $row['Name'] . "</td>"; 
       echo "<td>" . $row['Marks'] . "</td>"; 
       echo "<td>" . $row['value'] . "</td>"; 
      echo "</tr>"; 
     } 
     echo "<table>"; 
     //echo "</html></head></body>"; 
?> 

Antwort

1

Sie verwenden as $doc statt as $row hier.

foreach($cursor as $doc) { 
     echo "<tr>"; 
      echo "<td>" . $row['Name'] . "</td>"; 
      echo "<td>" . $row['Marks'] . "</td>"; 
      echo "<td>" . $row['value'] . "</td>"; 

Ändern es auf die Variable, die Sie verwenden müssen, $doc zu sein und nicht $row:

$m = new MongoClient(); 
    $db = $m->selectDB('MapData'); 
    $collection = new MongoCollection($db,'ETom4'); 

    $cursor = $collection->find(); 
    //echo "<html><head><body>"; 
    echo "<table>"; 
    foreach($cursor as $doc) { 
     echo "<tr>"; 
      echo "<td>" . $doc['Name'] . "</td>"; 
      echo "<td>" . $doc['Marks'] . "</td>"; 
      echo "<td>" . $doc['value'] . "</td>"; 
     echo "</tr>"; 
    } 
    echo "<table>"; 
    //echo "</html></head></body>"; 

HTML Stickler:

Sie auch 2 Zeilen kommentiert, das du Geben Sie Ihr Markup innerhalb <head></head> ein und platzieren Sie </html> vor </body> .

$m = new MongoClient(); 
    $db = $m->selectDB('MapData'); 
    $collection = new MongoCollection($db,'ETom4'); 

    $cursor = $collection->find(); 
    //echo "<html><head></head><body>"; 
    echo "<table>"; 
    foreach($cursor as $doc) { 
     echo "<tr>"; 
      echo "<td>" . $doc['Name'] . "</td>"; 
      echo "<td>" . $doc['Marks'] . "</td>"; 
      echo "<td>" . $doc['value'] . "</td>"; 
     echo "</tr>"; 
    } 
    echo "<table>"; 
    //echo "</body></html>"; 

Die Syntax/Struktur ist:

<html> 
    <head> 
    ... 
    </head> 

<body> 
... 
</body> 
</html> 

Sie auch <!DOCTYPE html> als erste Zeile hinzufügen.


Fußnoten:

Sie müssen auch sicherstellen, dass die Brieftasche Spalten.

Bei der Iteration über Zeilen in einer Schleife wird zwischen Groß- und Kleinschreibung unterschieden.

Daher würden Name und name als unterschiedlich angesehen werden.

Wenn (etwas oder alles) das oben genannte immer noch nicht für Sie funktioniert, dann können Sie irgendwo Fehler haben.

  • Also, auf Fehler prüfen.
+0

Dank, arbeiten gut, bemerkte ich das mein Fehler :) – Kavinda

+0

@Kavinda bitte Ihre alle Fragen Antworten überprüfen und versuchen, die Antworten zu markieren, die correct.Thanks sind. –