2017-05-30 62 views
0

只是为了解释这里要做什么:我有一个搜索功能,它使用用户输入[givenLocation]运行MySQL查询。它应该将查询的内容转储到列表框[self.lookuplist]。我的问题是,目前它只会转储第一个结果,即使我正在使用fetchall()函数。我是一名自学成才的python开发人员,但我无法从其他渠道找到有关此信息的任何信息。以下是我的代码:如何将MySQL fetchall()结果迭代到调色板列表框和中心结果中

def searchL_button(self): 

    i = 0 

    givenLocation = self.top3.searchEntry1.get() 
    searchLookup = ("SELECT Status, Serial, Product_Code, Location FROM Registers WHERE Location = %s") 
    cursor9.execute(searchLookup, [givenLocation]) 
    locRes = cursor9.fetchall() [i] 

    for i in locRes: 
     self.lookupList.insert(END, locRes) 

回答

1

您正在设置变量locRes以仅包含查询的第一个结果。将最后几行更改为以下内容

locRes = cursor9.fetchall() 

for curRes in locRes: 
    self.lookupList.insert(END, curRes) 
+0

非常感谢您的帮助! – codeLearnerCamel