我正在为我的帐户管理系统制作审批系统。注册后,用户在数据库中的条目为Approved,设置为false,但是当管理员登录时,我希望他返回一个帐户列表,其中批准的行为False。我已尝试过这个SQL语句,但我只得到第一个而不是全部。
c.execute("SELECT * FROM accounts WHERE approved=?", (False,))
ifapproved=c.fetchone()
print (ifapproved)
我尝试过使用for循环,但它只是重复了第一个未经批准的帐户。我该如何解决这个问题?
答案 0 :(得分:2)
您的execute
方法中有错误的syntx。
例如:
cur.execute(" SELECT Name,Price FROM Cars WHERE Id =:Id",{" Id":uId})
c.execute("SELECT * FROM accounts WHERE approved=:approved", {"approved":'false'})
//with or without the single quite to false.
rows = c.fetchall()
for row in rows:
print (row) //check all list of returned results
或
c.execute(" SELECT * FROM accounts WHERE approved =' False'")
c.execute(" SELECT * FROM accounts WHERE approved =' false'")
c.execute(" SELECT * FROM accounts WHERE approved =' 0'")
答案 1 :(得分:0)
尝试这种方式
stmt="""SELECT * FROM accounts WHERE approved=:APPROVAL"""
d["APPROVAL"]=False
c.execute(unicode(stmt), d)
ifapproved=c.fetchone()
print (ifapproved)