I have a login and view message function on my app. I wanted to pass the users’ id from check_username
to get_entries
where I can use it to filter the rows. But I don’t know how to pass the id. Here is my code.
database_handler.py
def check_username(username, password):
sql = "SELECT * FROM parent WHERE username = '" + username + "' and password = '" + password + "'"
cursor.execute(sql)
result = cursor.fetchone()
return result
def get_entries():
id = //
sql = f"SELECT * FROM entrymonitoring WHERE student_id = (SELECT mystudent FROM parent_mystudent WHERE parent = {id}) ORDER BY `date` DESC LIMIT 6"
cursor.execute(sql)
results = cursor.fetchall()
return results
LoginScreen.py
class LoginScreen(MDScreen):
def login(self):
# fetch login credentials
username = self.ids.username.text
password = self.ids.password.text
# check if the credentials are valid
login_check = database_handler.check_username(username, password)
if login_check:
Snackbar(text="Login successful").open()
else:
Snackbar(text="invalid username/password").open()
PublicScreen.py
class PublicScreen(MDScreen):
def load_posts(self):
self.ids.posts.clear_widgets()
entry = database_handler.get_entries()
for msg in entry:
msg_card = MDCard(
orientation="vertical",
padding="20dp",
size_hint=[None, None],
size=["500dp", "120dp"],
pos_hint={"center_x": .5, "center_y": .5}
)
msg_title = MDLabel(
halign="left",
text="AMSAI",
theme_text_color="Secondary",
size_hint_y=None,
height="40dp"
)
title_separator = MDSeparator(
height="1dp"
)
msg_body = MDLabel(
halign="left",
text="Your student exited the school grounds at " + str(msg[2]),
)
msg_timestamp = MDLabel(
text=str(msg[3]),
halign="right",
theme_text_color="Secondary",
size_hint_y=None,
height="5dp"
)
msg_card.add_widget(msg_title)
msg_card.add_widget(title_separator)
msg_card.add_widget(msg_body)
msg_card.add_widget(msg_timestamp)
self.ids.posts.add_widget(msg_card)
Can somebody help me on this one?
New contributor
zheni is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.