I am a newbie to Python and SQLite but I have a program where I want the user to enter how many items they want to order from a database table. They enter the products and quantities and the select query should return the items that match. It works except that it only prints out the last user entry and not all the user entries. I think the problem is around the select query line but I cannot figure it out. I have tried numerous variations but it either crashes or returns just the last user entry.
enter code here
for i in range(orderQty):
prodItem = int(input("Enter your Item to the List: "))
userOrder.append(prodItem)
prodQty = int(input("Enter the item quantity: "))
userQty.append(prodQty)
for j in range(len(userOrder)):
cursor = connection.execute("SELECT GTINnum, Item, CurrentStock,Cost from orderFile WHERE GTINnum= ?", (prodItem,))
for row in cursor:
print ("GTINnum =", row[0], "Item = ", row[1], "Cost = ", row[2], "Qty Ordered=",(prodQty), "\n")
prodCost = prodQty * row[2]
print ("Total product cost is: ", (prodCost))
userOrder[j]as parameter for the select instead ofprodItem. Similar forprodQtyfurther down. TakeuserQty[j]instead.