Reputation: 35
i am trying to output 2 different returns from sql queries in to the respective columns in a treeview widget using tkinter module in python 3.4 When i run command defined below the first column prints all the entries correctly but the name column prints the name of the first result in all rows instead of name per respective row. Any ideas on what im doing wrong?
def refreshtrade():
for i in treeview.get_children():
treeview.delete(i)
#order number
refreshtradein = conn.cursor()
refreshtradein.execute("SELECT increment_id FROM mg_ikantam_buyback_order")
#first name
names =conn.cursor()
names.execute("SELECT customer_firstname FROM mg_ikantam_buyback_order")# WHERE increment_id = 'buyback-%s'" %(tradeinentryfield.get() ))
for n in names:
for r in refreshtradein:
treeview.insert('',0,r,text = r, values=(n,'Mercedes', 'Purchased', '8-34-15'))
refreshtradein.close()
conn.close()
Upvotes: 0
Views: 1205
Reputation: 1903
Why are you using two different cursors and consequently two nested for loops? Are you aware how nested for loops are evaluated?
querycursor = conn.cursor()
querycursor.execute(SELECT increment_id, customer_firstname FROM mg_ikantam_buyback_order)
for row in querycursor:
print(row[0])
print(row[1])
Oh and regarding your where clause. Don't ever do parameter substitution like that. It is great security risk
See here how to do it correctly
Upvotes: 1