K
K
Kt0T02021-04-29 20:40:30
Python
Kt0T0, 2021-04-29 20:40:30

Check UserID by PostID sqlite3?

There is a Users table , it has postid and userid fields , how can I check for the presence of a specific userid by postid

My query:

"SELECT userid FROM users WHERE postid=?"

Ask if you don't understand.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
U
UberPool, 2021-04-29
@Kt0T0

conn = sqlite3.connect("users.db")
cursor = conn.cursor()
query = f"""SELECT * from questionnaires WHERE user_id={user_id}"""
cursor.execute(query)
check = cursor.fetchall()
if check:
#если пользователь есть
else:
#если нету

I think you can substitute your data.

G
Grandma Luda, 2021-04-29
@KirasiH

connect = sqlite3.connect("users.db")
cursor = connect.cursor()
cursor.execute("SELECT userid FROM users WHERE postid=?",(user_id,))
check = cursor.fetchall()
if check:
#если пользователь с таким id есть
else:
#если нету

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question