0
id | username | hash    | cash 
1      bill     efgeil    10000
2      tim      fgrgol    10000
3      jim      h6ju8k    10000

why does username_list_check[y]["username"] need the "["username"]"? Isn't the username col already selected?

Could I go username_list_check[y]["id"] and get the ids? If this is possible why?I clearly only selected username col.

username_list_check = db.execute("Select username FROM users")
for y in range (len(username_list_check)):
# check if username is in database. 
    if username_list_check[y][username] == request.form.get("username") or username_list_check[y]["username"] == username_list_check[-1]["username"]:
        return apology("password and password confirm fields do not match")

1 Answer 1

0

You're selecting ROWS from a database table, not columns. In short, you're selecting every row from a given table where the value of the column is equal to the given value.

Or, in other words, you're retrieving every row where the username in that row matches the name given.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

3
  • I get that I am selecting rows. I am curious if if I can go out of bounce by going username_list_check[y]["id"]? Would this work with the select statement I made? Also if I am selecting rows why do I need the code "username_list_check[y]["username"], specifically the "["username"]" part, if username is already added? Thanks for the help
    – grggthwrth
    Commented May 16, 2019 at 6:04
  • That I can't answer because I'm not up on that side of the code.
    – Cliff B
    Commented May 16, 2019 at 6:51
  • 1
    SELECT will return a list of records, each record being represented by a Python dict. With the ["username"], you select the specific field of that record. Would be more elegant to use the WHERE clause in the SQL statement than to check in Python.
    – Blauelf
    Commented May 16, 2019 at 10:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .