I'm trying to return 'search not found' when nothing is found in the database, but the program just jumps out the loop
I tried checking for 0
or ''
, but realized that the database returns NoneType
. I'm checking for None
now, but the code still does not get executed.
def search():
def searchmenu():
print('')
ans=str(input('Make another [s]earch or return to the [m]ain menu: '))
ans=ans.lower()
if ans=='s':
Inventory.search()
elif ans=='m':
menu=MainMenu()
menu.menuops()
else:
print('invalid menu option')
searchmenu()
mydb = mysql.connector.connect(host="localhost", user="root", password="", database="pharmd")
cursor = mydb.cursor()
query=str(input("Search: "))
if query != "":
cursor.execute('SELECT * FROM drugs WHERE name LIKE "%'+query+'%"')
results=cursor.fetchall()
if results != None:
for data in results:
print('found!')
print(data)
searchmenu()
else:
print('No results found')
else:
print('Please enter a valid search!')
print('')
Inventory.search()