S
S
Skrayvee2021-08-15 14:04:07
Python
Skrayvee, 2021-08-15 14:04:07

[AIOGRAM, SQLITE3] How to display the entire database in one message?

Everything needs to be in one message.

if adm_spis == spisbtns[0]:
    users = db.db_all()
    db_schet = len(users)
    users_list = {}
    for user in users:
      id = user[0]
      username = user[1]
      user_id = user[2]
      number = user[3]
      subscription = user[4]
      admi = user[5]
      blocked = user[6]
      ban = user[7]
    await msg.answer(f'<b>ВСЯ БАЗА ДАННЫХ </b>\n\n<i>Всего в базе: </i><code>{db_schet}</code>\n\n<b>ID: </b><code>{id}</code>\n<b>USERNAME: </b><code>{username}</code>\n<b>USER_ID: </b><code>{user_id}</code>\n<b>NUMBER: </b><code>{number}</code>\n<b>SUBSCRIPTION: </b><code>{subscription}</code>\n<b>BLOCKED: </b><code>{blocked}</code>\n<b>BAN: </b><code>{ban}</code>\n', parse_mode='html')


Only the last element from the base is returned:
ВСЯ БАЗА ДАННЫХ 

Всего в базе: 25

#ТУТ ДОЛЖНЫ ВЫВОДИТЬСЯ ОСТАЛЬНЫЕ ЭЛЕМЕНТЫ

ID: 25
USERNAME: YAR_Diana_Kondakova
USER_ID: 837344062
NUMBER: None
SUBSCRIPTION: 0
BLOCKED: 0
BAN: 0


I thought to write to the dictionary, but then it will not be possible to display it with html tags

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2021-08-15
@Skrayvee

users_listyou don't use it anywhere. Why then is it in the code?

for user in users:
      id = user[0]
      username = user[1]
      user_id = user[2]
      number = user[3]
      subscription = user[4]
      admi = user[5]
      blocked = user[6]
      ban = user[7]

And where are you assigning it? Iterated, and then what?
Naturally there will be only the last element.
Grab a Python textbook and learn.
Still think that will be when at you will be from several hundred users in a DB.
UPD:
how to write correctly to display everything with html tags

like this (finished for yourself):
users = [
    ('Vasya', '12345', '[email protected]'),
    ('Petr', '7654', '[email protected]'),
    ('Irina', '142340385', '[email protected]'),
    ('Solomon', '981234125', '[email protected]'),
]

with_markup = ' '.join(map(lambda x: f'name: {x[0]}\nid: {x[1]}\nemail: {x[2]}', users))

print(with_markup)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question