Answer the question
In order to leave comments, you need to log in
How to display data from msql?
I have products in the database, but somehow I need to display them, I could only output them individually, help plz.
if(text === 'Магазин'){
man = connection.query('SELECT * FROM `products`', function(error,results){
if(error) {throw error}
const name = results[1]['name'];
const price = results[1]['price'];
bot.sendMessage(chatId, `Продукты: \nИмя: ` + name + ` Цена: ` + price);
bot.sendMessage(chatId, results[1]['name']);
});
}
Answer the question
In order to leave comments, you need to log in
We use a loop:
if(text === 'Магазин'){
man = connection.query('SELECT * FROM `products`', function(error,results){
if(error) {throw error}
for (let i in results) {
bot.sendMessage(chatId, `Продукты: \nИмя: ${results[i]['name']} Цена: ${results[i]['price']}`);
bot.sendMessage(chatId, results[i]['name']);
}
});
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question