我的目标是在文本区域内显示所有电子邮件。
app.get('/mongodata', function(req, res){
console.log('Request Successful');
console.log('_parsedUrl.query: ' + req._parsedUrl.query);
var url_parts = requestUrl.parse(req.url, true);
var query = url_parts.query;
var dataVersion = req.query.dataVersion;
MongoClient.connect(url, function (err, db) {
if (err) {
console.log('Unable to connect to the mongoDB server. Error:', err);
} else {
console.log('Connection established to', url);
var collection = db.collection(query.collectionName);
collection.find({DataVersion: query.dataVersion}).toArray(function(err, docs) {
//console.log(docs);
res.json(docs);
assert.equal(null, err);
db.close();
});
}
});
});
它应该将所有信息回显到这里:
<?php
$q = "SELECT * FROM `Clients`";
$userData = mysql_query($q);
while($user = mysql_fetch_assoc($userData)){
echo $user['Email'];
}
?>
我从数据库中获取信息很好,但我不确定如何将所有数据回显到单个文本字段中。
答案 0 :(得分:2)
PHP代码
$userData = mysql_query($q);
$userEmails = array();
while($user = mysql_fetch_assoc($userData)){
$userEmails[] = $user['Email'];
}
HTML(以逗号分隔的电子邮件字符串为例)
<input type="text" value="<?php echo implode(', ', $userEmails); ?>" />
答案 1 :(得分:0)
您需要按以下方式进行: -
<?php
$q = "SELECT * FROM `Clients`";
$userData = mysql_query($q);
$email = array(); // create an array
while($user = mysql_fetch_assoc($userData)){
$email[] = $user['Email']; // assign each email to that array
}
?>
<textarea><?php echo implode(','$email);?></textarea> // implode the array by `,` now all emails will show wiith `,` seperation.
注意: - 这是你需要做的事情。检查变量并进行必要的更改。感谢。