How to populate a treeview with results from many tables?
I've a set of tables: athletes, grades, categories, rel_ath_grad_cath.
| athletes | grades | categories | rel_ath_grad_cath |
|---|---|---|---|
| id_ath | id_grad | id_cat | id_ath |
| name_ath | name_grad | name_cat | id_grad |
| id_cat |
I want my treeview to show: id_ath | name_ath | name_grad | name_cat
When I work on a single table, there's no drama
def afficher_donnees():
my_conn.execute('SELECT * FROM `athletes`')
rqsa_aths = my_conn.fetchall()
for ath in rqsa_aths:
trv.insert('', 'end', values=(ath[0], ath['1'], ath[2]))
It gives me all of my athletes table (id, firstname, and lastname).
But when I want to take all the rest there's my nightmare
The code I tried:
def afficher_donnees():
# Select all athletes
my_conn.execute('SELECT * FROM `athletes`')
rqsa_aths = my_conn.fetchall()
# nb_athl
nb_athl = len(rqsa_aths)
i = 0
data_agt = []
# I want to take the grad corresponding to the ath
for ath in rqsa_aths:
while nb_athl+1 > i:
# For the i ath i take the id
id_ath = ath[i]
name = ath[1]
# Then take the grad which corresponding to the id
my_conn.execute('SELECT `name_grad` FROM `grades`
JOIN rel_ath_grad_cath RAGC
ON RAGC.id_grad = grades.id_grad
JOIN athletes ATH
ON RAGC.id_ath = ATH.id_ath
WHERE ATH.id_ath = %s' %id_ath)
grad_ath = my_conn.fetchone()
trv.insert('', 'end', values=(ath[0], ath['1'], grad_ath[0]))
i = i+1
But that is not working because nothing appears on the screen and no mistakes are shown in the console.
Someone to help me seeing what's wrong?