I try to create a
html element for each element in an array but It doesn't work can you help me ?
my node js code :
con.connect(function(err) {
// if (err) throw err;
console.log("Connected!")
con.query( 'SELECT * FROM `commentairesapplicationscommunautaire` ', function (error, results, fields) {
for (var i = 0; i < results.length; i++){
var zeuzryueartt = results[i].contenu
console.log(zeuzryueartt)
res.end('<p> '+ zeuzryueartt +' </p>')
}
});
});
this code looks like : <p> rrr </p>
But is wrong for my case
Thanks
Sterling Archer
22.5k19 gold badges86 silver badges121 bronze badges
1 Answer 1
You are ending the response stream on the very first step. You need to only call end once you built entire response html.
con.connect(function(err) {
// if (err) throw err;
console.log("Connected!")
con.query( 'SELECT * FROM `commentairesapplicationscommunautaire` ', function (error, results, fields) {
const entireHTML = results.map(result => `<p>${result.contenu}</p>`).join('')
res.end(entireHTML)
});
});
Sterling Archer
22.5k19 gold badges86 silver badges121 bronze badges
answered Jun 13, 2018 at 16:20
Yury Tarabanko
45.1k10 gold badges88 silver badges99 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js
rescoming from? Iscon.connectinside of a node handler? Regardless, you can only useres.end/send/jsononce per callback. You'll have to concatenate these into a single variable and send that back