0

I'm doing pset9 "Finance" and I've designed the two tables in the database, one with purchases and the other with transactions. Now when I render the index page, the shares of only one company is displayed a lot of times. Here is the code

def index():
    """Show portfolio of stocks"""
    # Query database for user's stocks
    users = db.execute("SELECT cash FROM users WHERE id = :user_id", user_id=session["user_id"])
    stocks = db.execute(
        "SELECT SUM(shares) FROM purchases WHERE username = :user_id GROUP BY symbol", user_id=session["user_id"])
    places = db.execute("SELECT symbol FROM purchases WHERE username = :user_id ", user_id=session["user_id"])
    company = db.execute("SELECT symbol FROM purchases WHERE username = :user_id GROUP BY symbol", user_id=session["user_id"])
    for companies in company:
        if companies in company:
            lk1=lookup(companies['symbol'])
            db.execute("UPDATE trans SET company = :place ,stocks = :stocks WHERE userid = :uid",place = lk1['symbol'], stocks = stocks[0]['SUM(shares)'], uid = session["user_id"])
            share_value = lookup(companies['symbol'])
            db.execute("UPDATE trans SET Current_val = :share_value WHERE company =:company", share_value=share_value['price'],company=lk1['symbol'])

    value = db.execute("SELECT cash FROM users WHERE id =:uid", uid=session["user_id"])
    trans = db.execute("SELECT * FROM trans WHERE userid = :uid", uid=session["user_id"])
    f_val=value[0]['cash']
    return render_template("index.html", trans=trans,f_value=f_val)```
  • List item

Purchases Table Trans Table Trans Table full Output top Output bottom

You must log in to answer this question.

Browse other questions tagged .