gpt4 book ai didi

php - 使用 HTML 文件显示 MongoDB 集合

转载 作者:可可西里 更新时间:2023-11-01 10:04:04 25 4
gpt4 key购买 nike

<body>
<?php
$server = "mongodb://localhost:27017/test";
// connect to mongodb
$m = new MongoClient($server);
// select a database
$db = $m->test;
?>

try{
// Connecting to server
$c = new MongoClient( $server );
}catch(MongoConnectionException $connectionException){
print $connectionException;
exit;
}

$data = "<table style='border:1px solid red;";
$data .= "border-collapse:collapse' border='1px'>";
$data .= "<thead>";
$data .= "<tr>";
$data .= "<th>Name</th>";
$data .= "<th>UserID</th>";
$data .= "<th>Email</th>";
$data .= "<th>Sites Links</th>";
$data .= "<th>Imgaes</th>"
$data .= "</tr>";
$data .= "</thead>";
$data .= "<tbody>";

try{
$collection = $db->links;
$people = $collection->find();
foreach($people as $document){
$data .= "<tr>";
$data .= "<td>" . $document["Name_of_the_person"] . "</td>"; // Name
$data .= "<td>" . $document["userID"]."</td>"; // UserID
$data .= "<td>" . $document["email"]."</td>"; // Email
$data .= "<td>" . $document["links"]."</td>"; // Sites
$data .= "<td>" . $document["imagesurl"]."</td>"; // Images
$data .= "</tr>";
}
$data .= "</tbody>";
$data .= "</table>";
echo $data;

}catch(MongoException $mongoException){
print $mongoException;
exit;
}

</body>
</html>

我真的很想知道代码有什么问题。

谢谢

最佳答案

我同意 vmr 的评论。但是如果你仍然想使用代码:

<?php
$server = "mongodb://localhost:27017/test";
// connect to mongodb
$m = new MongoClient($server);
// select a database
$db = $m->test;

?>

<table style='border:1px solid red border-collapse:collapse' border='1px'>";
<thead>
<tr>
<th>Name</th>
<th>UserID</th>
<th>Email</th>
<th>Sites Links</th>
<th>Images</th>
</tr>
</thead>
<tbody>


<?php
try{
$collection = $db->links;
$people = $collection->find();
foreach($people as $document){
echo "<tr>";
echo "<td>".$document["Name_of_the_person"]."</td>"; // Name
echo "<td>".$document["userID"]."</td>"; // UserID
echo "<td>".$document["email"]."</td>"; // Email
echo "<td>".$document["links"]."</td>"; // Sites
echo "<td>".$document["imagesurl"]."</td>"; // Images
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
}catch(MongoException $mongoException){
print $mongoException;
exit;
}
?>

我知道帖子是旧的。但如果您仍在寻找解决方案,它可能会有所帮助。

关于php - 使用 HTML 文件显示 MongoDB 集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26716035/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com