Answer the question
In order to leave comments, you need to log in
How to display data from database in inline buttons?
Good evening, I am writing an asynchronous bot in the aiogram library and I don’t know how to make it so that in the inline button I push all the values from the database where there are specialists.
I will be grateful for help.
@dp.message_handler(lambda message: message.text == "Записатися на прийом ")
async def specialist(message: types.Message):
read = await bot_db.sql_read2()
for ret in read:
await bot.send_message(message.from_user.id, text=f"{message.from_user.last_name} виберіть спеціаліста", reply_markup=InlineKeyboardMarkup().insert(InlineKeyboardButton(f'{ret[0]}', callback_data=f'spel {ret[0]}')))
Answer the question
In order to leave comments, you need to log in
for i, n in enumerate(menu_dict):
# print(menu_dict[i][0])
id = menu_dict[i][0]
name = menu_dict[i][1]
items = menu_dict[i][2]
# print(f"{name}{items}")
menu = InlineKeyboardMarkup(row_width=1)
for q, w in enumerate(items):
callback_data = f"{id}_{q}"
button = InlineKeyboardButton(text=w[0], callback_data=callback_data)
menu.insert(button)
# print(f"{name}-{w} {id} - {button}")
menu.insert(InlineKeyboardButton(text="отмена", callback_data="cancel"))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question