Answer the question
In order to leave comments, you need to log in
How to display the result?
With xhr come post request an array of values selected by checkboxes, for example ['США', 'Россия', 'Германия']
And in the route I try to display the results of a request from different countries
app.post('/films', function (req, res) {
// подключение к БД
let arr = []
for (let i = 0; i < 10; i++) {
let country = req.body.county;
let rand = country[Math.floor(Math.random() * country.length)]
connection.getConnection(function (err, connection) {
if (err) console.log(err);
connection.query
('SELECT * FROM `films` WHERE `country` = ? ORDER BY RAND() LIMIT 1', rand,
function (err, result, fields) {
if (err) console.log(err);
console.log(result)
arr.push(result)
console.log(arr) // выводит массив с результатами
})
});
}
// res.render('films', {
// title: 'Body',
// movies: arr,
// folder: 'films'
// })
console.log(arr) // но тут показывает []
res.end()
});
console.log(arr) // []
connection.query
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question