title: showing data from database into tkinter not working
body: <p>I have defined a function here and it is supposed to work correctly because im using a similar function somewhere else but without giving any conditions(where.. like or regexp) and it works fine there, when i use regexp and all it does not give an output. Why is that? Thanks in advance :)</p>
  
  <p>Code:</p>
  
  <pre><code>def search():
      log = Toplevel(root)
      log.title('View all customers')
      def db():  
          selected = drop.get()
          result_win = Toplevel(log)
          result_win.title('Search result')
  
          con = mysql.connect(host='localhost', user='root',
                                  password='*****', database='BOOK')
          c = con.cursor()
  
          c.execute(f"SELECT * from books where '{selected}' regexp 
          '{e_sch.get()}';")
          result = c.fetchall()
          index=0
          for index, x in enumerate(result):
              num = 0
              for y in x:
                  lookup_label = Label(result_win, text=y)
                  lookup_label.grid(row=index+1, column=num)
                  num +=1
          con.close()        
          l1 = Label(result_win,text='Sl.No',font=font_text)
          l2 = Label(result_win,text='Title',font=font_text)
          l3 = Label(result_win,text='Authors',font=font_text)
          l4 = Label(result_win,text='Subject',font=font_text)
          l5 = Label(result_win,text='Availablity',font=font_text)
          btn_ext = Button(result_win,text='Exit',font=font_text,command=result_win.destroy,borderwidth=2,fg='#eb4d4b')
  
          l1.grid(row=0,column=0,padx=20)
          l2.grid(row=0,column=1,padx=20)
          l3.grid(row=0,column=2,padx=20)
          l4.grid(row=0,column=3,padx=20)
          l5.grid(row=0,column=4,padx=20)
          btn_ext.grid(row=index+2,columnspan=7,ipadx=540)
  
      global a
      l = Label(log,text='Search',font=Font(family='helvetica', size='20'))
      drop = ttk.Combobox(log,value=['Search by....','Sl.no','Title','Authors','Subject','Availablity'])
      drop.current(0)
      l2 = Label(log,text='Enter',font=font_text)
      e_sch = Entry(log)
      b_sch = Button(log, text='Search book', command=db, font=font_text) 
      b_ext = Button(log, text='Exit', command=log.destroy, font=font_text) 
      a = drop.get()
      l.grid(row=0,columnspan=3,pady=20)
      drop.grid(row=1,column=0,columnspan=3)
      l2.grid(row=2,column=0,padx=(20,0))
      e_sch.grid(row=2,column=1, padx=30, ipady=5,pady=20)
      b_sch.grid(row=3,column=0,columnspan=3,ipadx=200)
      b_ext.grid(row=4,column=0,columnspan=3,ipadx=237)
  </code></pre>
  
  <p>Sometimes i get this error too <code>UnboundLocalError: local variable 'index' referenced before assignment</code></p>