質問

I am making an approval system to my account management system. Upon registering the user has an entry in the database as Approved which is set to false, but when an admin logs in, I want him to be returned a list of accounts with the approved row as False. I have tried with this SQL statement but am only getting the first not all of them.

c.execute("SELECT * FROM accounts WHERE approved=?", (False,))
ifapproved=c.fetchone()
print (ifapproved)

I have tried using a for loop but it just repeats the first account which is unapproved. How can I fix this?

役に立ちましたか?

解決

You have wrong syntx in your execute method.

For example:

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
  

or

c.execute("SELECT * FROM accounts WHERE approved = 'False'")

c.execute("SELECT * FROM accounts WHERE approved = 'false'")

c.execute("SELECT * FROM accounts WHERE approved = '0'")

他のヒント

Try in this way

stmt="""SELECT * FROM accounts WHERE approved=:APPROVAL"""
d["APPROVAL"]=False

 c.execute(unicode(stmt), d)
ifapproved=c.fetchone()
print (ifapproved)
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top