0

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()

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

3 Comments

thanks for the feedback and no im not aware so thanks for the insight. i will try to make sense of your response as i am very new to coding and it is not intuitive to me yet but i will respond with my results. thanks again
i get a AttributeError: 'tuple' object has no attribute 'increment_id' error when i try your suggestion
thanks man, im still very new to this obviously and i appreciate you help. that made it output exactly what i needed. i tried the non security risk sql query exploit but i get a syntax error when i put the comma :/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.