0

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?

1
  • i suppose remove , after false and try Commented Apr 23, 2014 at 10:16

2 Answers 2

2

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'")

Sign up to request clarification or add additional context in comments.

9 Comments

wt is difference between ur answer and Below one
Does not work, still getting the first account only.
syntax it is? have u tried without the quetos on False
I removed the quotes and kept it as False, because approved is equal to the boolean False or True, not the string 'False' or 'True'
try now , you have used fetchOne ...with a select * query so fetch all as above and play with the row in the for loop ..cheers!
|
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)

1 Comment

I get an error, d is not globally defined. I am using Python3 btw.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.