現在、MySQL データベースと対話するプログラムを作成していて、問題が発生しています。ご覧のとおり、ユーザーが入力したバーコードに対応する製品を製品テーブルで検索するクエリを作成しました。
ユーザーが入力したバーコードが製品テーブルで見つかった場合、バーコード入力に対応する製品が在庫の製品と同じである在庫テーブルの「金額」フィールドを 1 増やしたいテーブル。
ご覧のとおり、変数を for ループに割り当てて、そのように機能させようとしましたが、機能していません。誰かがそれを行う方法について何か考えがありますか?
import MySQLdb
def look_up_product():
db = MySQLdb.connect(host='localhost', user = 'root', passwd='$$', db='fillmyfridge')
cursor = db.cursor (MySQLdb.cursors.DictCursor)
user_input=raw_input('please enter the product barcode that you wish to checkin to the fridge: \n')
if cursor.execute("""select * from products where product = %s""", (user_input)):
db.commit()
result_set = cursor.fetchall ()
#i want here to assign a variable to this for loop and the line below = for product in result_set:
print "%s" % (row["product"])
cursor.execute('update stocks set amount = amount + 1 where product = %s', (#here i want the result of the for loop))
db.commit()
else:
print 'no not in products table'
どうもありがとう。