0

Hi, I’m stuck with pset7 finance for a while. I managed to implement quote and buy functions but got stuck with index. Right now my database has two tables, users an portfolio. Users table is structured as id(unique), username, hash, cash, and cashbalance, Portfolio table is structured with the symbol, shares, price, userid, date and time rows.
The problem appears as follows: whenever the current user has bought one, two or more shares , index page always shows html table with multiple instances of only the first bought stock, other transactions don’t appear in the table. Here is my application py index function and buy function, can someone please help me with this. Much appreciated!

EDIT: Ok, I changed it according to your suggestions, but still having the same problem? EDIT2: Ok, i got it, but now I can't pull the symbol data with lookup function to get the current price of each stock?

enter image description here

2 Answers 2

1

This for holding in holdings: processes the first element in holding, and then returns from the function. The return needs "less indent" so it executes when the for loop is complete.

Warning: stocks will hold the values of the last holding processed. (more later).

symbol and shares are always set to the first element (index 0) in holdings (eg symbol = holdings[0]['stock']).

I'm speculating that index.html iterates over stocks, which has 5 elements, since the output shows 5 rows, but the index route is only sending 1 row.

stocks needs to be some kind of nested object, like a list of dictionaries. Since holdings is already a list of dictionaries consider this - if you add new key/value pairs to holdings (eg holding['name'] = symbolinfo['name']), you could send that to index.html and have everything you need.

5
  • I tried, but I still have the same problem, can you please check my code again? Thank you.
    – bobby_pin
    Commented Apr 15, 2017 at 8:46
  • for holding in holdings iterates through each element in holdings. Why would you then holding = {}, ie set it to an empty dictionary? See emphasis added to answer for "the part you missed". Commented Apr 15, 2017 at 10:39
  • Ok I have fixed that, but now I can't get the current stock price with lookup function, how to pull current stock price? symbolInfo = lookup(symbol['symbol']) gives me error NameError: name 'symbol' is not defined
    – bobby_pin
    Commented Apr 16, 2017 at 7:12
  • There is no such thing as symbol['symbol']. Read your code carefully. Commented Apr 16, 2017 at 10:49
  • ok sorted it out, of course I had to use lookup according to the stock that i already own in my holdinds... just got confused that in that way I would be displaying the price that I paid at the time of purchase rather than actual market price. Thanks a lot
    – bobby_pin
    Commented Apr 17, 2017 at 5:00
0

here's the table

C$50 Finance

Parts Logout

Symbol Name Shares Price TOTAL CASH 10000.0000

        Copyright © John Harvard

when im clicking the parts in the above there is an error like this: Fatal error: Table 'pset7.parts' doesn't exist in C:\xampp\htdocs\pset7\includes\functions.php on line 139

what should i do?

You must log in to answer this question.

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