V
V
VladRF4R4R2021-12-10 22:30:16
Python
VladRF4R4R, 2021-12-10 22:30:16

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

1 answer(s)
N
Nickolay Tapokpy, 2021-12-11
@Tapokpy

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"))

I did this, but not from the database, but from the dictionary.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question