Answer the question
In order to leave comments, you need to log in
How to compare values from a database?
Good day.
There is a database that stores a person's data. I compare by id, but it doesn't work for me.
Here is the code:
cursor = db.cursor()
cursor.execute("SELECT telegram_user_id FROM users")
result = cursor.fetchall()
if message.from_user.id not in result: # вот так не работает, работает только если писать result[0] и т.д.
print("Выдает не зареган... Даже, если этот id есть в бд")
else:
print("Вы уже зареганы в бд")
Answer the question
In order to leave comments, you need to log in
In result you get an array of objects with one field. First you need to get the id array. This is to check for entry.
In your case, it's better to add where telegram_user_id = message.from.user_id to the query.
And check if the number of results in the sample is greater than or equal to 1, then it is registered.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question