Tags

, , , , , , ,

pset7: C$50 Finance, Stock portfolio

Course: Harvard’s CS50

Problem Set 7: C$50 Finance

pset7 is about building a website using PHP/HTML/CSS/SQL/Js (and not C).

This problem set asks you to create a fake stock market, where users can ‘buy’ and ‘sell’ stocks. If you want an example, pick one of the many stock market game websites out there (economics courses often use those as a learning tool), or look at the staff’s implementation.

One problem with this assignment is… when to stop?

The longer I worked on it the more changes I found to do, tweaks, design changes, theme changes, features to add etc. So I just decided to stop at one point, and that was that.

If I was to start-over from scratch I’d focus on the initial DB design a lot more; many times I had to go back to the code and modify something because I thought of a better way of doing something on the DB side of the assignment. (one big example: the views)

The current version of my database tables & views still has a few things the code doesn’t use. Some aspects of the DB design took me a while to figure out, quite late into the assignment. For instance this little snip, from pset7_view_users_totals, had me scratching my head for a few days…:


IFNULL(SUM(portfolios.number_of_stocks*cache.price),0) AS stock_value,

Anyways, here’s how the DB tables could be set up.

jharvard_pset7_tables.sql (view | download)
jharvard_pset7_views.sql (view | download)
And the entire project: pset7_finance.zip

As an added safety the constants.php file must be two dirs up form the includes folder (see common.php), so that if/when I copied the entire project over from system to system I didn’t also overwrite ‘that’ system’s DB info. (it’s a common trick in php projects.)

Enjoy!

P.S. If you’re completely unfamiliar with web languages like PHP, HTML, CSS and SQL you might want to look at Harvard’s CS75, another OCW course.