I'm trying to figure out why the folder(item) function is not working the 'correct" way. It is working if I use the for loop and doing a search. I'm getting the ID. But I like to do is to use MySQL query, but it returns 'None'
Just to make sure, if I type in SELECT * FROM grocery WHERE item = "Test 1";
in MySQL it finds the ID.
The line I can't get to work is the index = cursor.execute("SELECT * FROM grocery WHERE item =%s", (item))
def showAll():
cursor = conn.cursor()
cursor.execute("SELECT * FROM grocery")
result = cursor.fetchall()
return result
def insert(item, path):
cursor = conn.cursor()
cursor.execute("INSERT INTO grocery (item, path) VALUES (%s, %s)", (item, path))
conn.commit()
def delete(index):
cursor = conn.cursor()
cursor.execute("DELETE FROM grocery WHERE id=%s", (index,))
conn.commit()
def folder(item):
display = showAll()
for d in display:
print(d)
if(item in d):
print("ID = ", d[0])
cursor = conn.cursor()
index = cursor.execute("SELECT * FROM grocery WHERE item =%s", (item))
return index
print(folder("Test 1"))
#SELECT * FROM grocery WHERE item = "Test 1";